# Adding values together only if tag is true

**URL:** <https://forum.inductiveautomation.com/t/adding-values-together-only-if-tag-is-true/93640>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 23, 2024, 11:54pm UTC](https://forum.inductiveautomation.com/t/adding-values-together-only-if-tag-is-true/93640 "2024-07-23T23:54:34Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 24, 2024, 12:51am UTC](https://forum.inductiveautomation.com/t/adding-values-together-only-if-tag-is-true/93640/21 "2024-07-24T00:51:52Z")

</div>

```python
b = "[default]779/CabTrimAGVs/AGVProgram/AGV%02d/B2"
r = "[default]779/CabTrimAGVs/AGVStatus/AGV%02d/R5"
tagPaths = [b % i for i in xrange(0, 160)] + [r % i for i in xrange(0, 160)]

```

(assumptions made)

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 24, 2024, 12:52am UTC](https://forum.inductiveautomation.com/t/adding-values-together-only-if-tag-is-true/93640/22 "2024-07-24T00:52:21Z")

</div>

only a leading 0 until 2 digits. so 10 is the first one without the leading 0.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 24, 2024, 12:58am UTC](https://forum.inductiveautomation.com/t/adding-values-together-only-if-tag-is-true/93640/23 "2024-07-24T00:58:25Z")

</div>

Ok. I would install my Integration Toolkit module and then make an expression tag with this:

```python
sum(
	transform(
		tags(
			flatten(
				forEach(
					159,
					stringFormat("[default]779/CabTrimAGVs/AGVProgram/AGV0%02d/B2", idx()+1),
					stringFormat("[default]779/CabTrimAGVs/AGVStatus/AGV0%02d/R5", idx()+1)
				)
			),
			100
		),
		forEach(
			value(),
			if(
				(idx() & 1 = 0) && coalesce(it()[1], false),
				coalesce(value()[idx()+1][1], 0.0),
				0.0
			)
		)
	)
)

```

No script. Set the expression tag to event driven execution mode.

(Depending on your Ignition version, you may need to restart your gateway for my toolkit expressions to be available in expression tags.)

The second argument to `tags()` is the dwell factor, to make it efficient as batches of tag changes arrive. But it will stay within that dwell factor of real-time.

{ Edit: made an efficiency tweak. And a subscript fix. Further efficiencies could be gained by moving the tagpath generation to another expression tag.}

{ Further comment: I'm not sure I got the tag order right--the expression assumes the boolean is first, then the numeric, in each pair. If I'm backwards, just swap the two `stringFormat()` subexpressions. }

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 24, 2024, 12:59am UTC](https://forum.inductiveautomation.com/t/adding-values-together-only-if-tag-is-true/93640/24 "2024-07-24T00:59:56Z")

</div>

Awesome thanks! Ill give it a try.

[Previous page](https://forum.inductiveautomation.com/t/adding-values-together-only-if-tag-is-true/93640.md?page=1)
