# Using multiple IF statements with OR in Tag Properties

**URL:** <https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [April 5, 2020, 2:44pm UTC](https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690 "2020-04-05T14:44:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhicks1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mhicks1/32/14121_2.png) [@mhicks1](https://forum.inductiveautomation.com/u/mhicks1)\
**Post date:** [April 5, 2020, 2:44pm UTC](https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690/1 "2020-04-05T14:44:39Z")

</div>

Hello, I am trying to populate a Numeric Label Value using If Or, If Or…7 times.  
IF the Material in a specific Bin is being used by any feeder (1-7) then display the Rate value of that feeder. I am able to get the value I want if I only use 1 If condition.

When I add the second If condition (after an OR at the end of the first If), All i get back as a result is 1 Has anyone needed to create code for a similar application?

Below is the Template for the Value and the code I am using. Thanks in advance for any help.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7b7b16a0522c6c2c6611a847d740bbc6086001e1.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0db17e7092acbc0fc299f6e61d4c1c9343959991.png)  
The numeric values at the end of each line prior to the OR are only used for troubleshooting. They will end up being " " or “0”

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [April 5, 2020, 4:05pm UTC](https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690/2 "2020-04-05T16:05:46Z")

</div>

Each of your if statements returns either the actual feed rate or the value after the second comma. The or instructions are then applied and return true or 1 as long as one of the if statements gives a non-zero result. Nesting your if statements would give you what you’re looking for:

```java
if(condition,
	trueResult,
	// Each false result is a nested if.
	if(condition,
		trueResult,
		if(condition,
			trueResult,
			// Final false result for if all ifs are false.
			falseResult
		)
	)
)

```

Also consider replacing your `tag()` instructions with properties that use indirect tag bindings.

**EDIT** : An easier solution: replace the `OR` instructions with `+` to concatenate all the if results (seeing as you’ll have them return `""` when they’re false). If you do this, you may need to convert the if results to strings and wrap the whole thing in a numberFormat.

---

<div class="post-metadata">

**Author:** ![mhicks1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mhicks1/32/14121_2.png) [@mhicks1](https://forum.inductiveautomation.com/u/mhicks1)\
**Post date:** [April 5, 2020, 4:31pm UTC](https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690/3 "2020-04-05T16:31:13Z")

</div>

Thank you for replying witman, I have tried using bindings instead of tags but I kept getting “Nesting not Allowed” errors. Would your suggestion work with nesting or would it have any nesting at all do you think?

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [April 5, 2020, 4:41pm UTC](https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690/4 "2020-04-05T16:41:45Z")

</div>

The second solution–the edit-- should work with just replacing your `||` with `+`. If you get a type error, surround your if true results with `toStr()`. The first solution will also work, but gets a bit ugly the deeper the nesting goes. The nesting referred to here is unrelated to the error you got.

The nesting error you had before was due to trying to include dynamic properties in a tag path in an expression without using the `tag()` instruction. You can’t do that. You can, however, avoid using `tag()` by using indirect tag bindings on custom properties.

To switch this to indirect tag bindings on custom properties:

1. Create custom properties for each tag you’re referencing via `tag()`. Something like `feeder1Material, feeder1PercentSet, feeder1RateActual, feeder2Material`…
2. Apply an [indirect tag binding](https://docs.inductiveautomation.com/display/DOC80/Indirect+Tag+Bindings+in+Vision) to each of those tag properties to connect the property to the correct tag.
3. Use the `feeder1Material, feeder1PercentSet, feeder1RateActual`, etc. properties in place of your `tag()` instances in the expression.

---

<div class="post-metadata">

**Author:** ![mhicks1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mhicks1/32/14121_2.png) [@mhicks1](https://forum.inductiveautomation.com/u/mhicks1)\
**Post date:** [April 5, 2020, 11:46pm UTC](https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690/5 "2020-04-05T23:46:29Z")

</div>

Hi witman, Thanks for the awesome suggestions. I used the EDIT you suggested and all it took was changing the OR’s to ADDITION and it worked immediately. I then modified a bit more to use some custom properties. See Below…

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f0af29a69311a6d113cac741411ce31d17ae0337.png)

Thanks again. 🙂

---

<div class="post-metadata">

**Author:** ![Dmart](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dmart/32/13427_2.png) [@Dmart](https://forum.inductiveautomation.com/u/Dmart)\
**Post date:** [April 6, 2020, 6:30pm UTC](https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690/6 "2020-04-06T18:30:15Z")

</div>

@witman  
So I’ve seen you mention using the indirect tag bindings on custom properties vs. not using the tag() function. For the most part I’ve been using the indirect way for a long time.  
But I’m kinda curious why you recommend doing it that way.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [April 6, 2020, 7:14pm UTC](https://forum.inductiveautomation.com/t/using-multiple-if-statements-with-or-in-tag-properties/33690/7 "2020-04-06T19:14:46Z")

</div>

@Dmart, a few reasons I avoid using `tag()`:

1. **Performance** :

> [@Nesting Not Allowed while using Properties in a Template to turn on a Light](http://forum.inductiveautomation.com/t/nesting-not-allowed-while-using-properties-in-a-template-to-turn-on-a-light/33609/16):
>
> Yes, there is. If the items that comprise your tagpath are updated, even if yielding the same result path, the entire expression containing the tag() function will have to execute. With indirect binding, this doesn’t happen. The strings themselves have to be reconstructed every time, even if not changing, slowing down the final expression execution. There are a few cases with computed gateway tags where the tag() expression is the only good way to do indirection, and the dynamic stuff above…

1. **Readability** : the OP's expression would be much shorter and easier to read if made of short custom property names rather than the `tag()` expressions.

2. **Read/write Binding** : This only matters when you need to write, but the `tag()` instruction doesn't support writing.

3. **Flexibility/maintainability** : I find it's generally easier to test/troubleshoot/add to something broken into simple component parts, rather than one big expression. Although I'll admit to creating a few multi-screen expressions early on, I probably wouldn't do that if recreating them now.
