# Multiple condition Expression - Nested If Statement?

**URL:** <https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105>\
**Category:** Ignition\
**Created:** [July 20, 2022, 7:29am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105 "2022-07-20T07:29:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 7:29am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/1 "2022-07-20T07:29:07Z")

</div>

I am trying to make a comparison between 2 tags in an expression tag to show if my symbol is running, faulted, or stopped

what I am going for is

if Tag 1 and Tag 2 are both true = we are in a “running” state  
if nothing is true = we are in a “stopped” state

if only tag 1 is true = “faulted”  
if only tag 2 is true = “faulted”

I tried using the example from the user manual but I kept having it so if both tags were true it was giving me the “Tag 2 is positive” result instead of the “both tags are positive result” , So I don’t get it because I assumed that spot is for 1st condition false 2nd condition true ,but its the result I get for both conditions being true?

`if` `({tag1} > ` `0` `, ` `if` `({tag2} > ` `0` `, ` `"Both Tags are positive."` `, ` `"Tag 1 is positive."` `), ` `if` `({tag2} > ` `0` `, ` `"Tag 2 is positive."` `, ` `"Neither Tag is positive."` `))`

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 7:40am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/2 "2022-07-20T07:40:57Z")

</div>

You say your tags can be `true`, so are they booleans ?  
If so, I’d suggest something like this:

```auto
if (tag1 && tag2, "both are true",
    if (tag1 || tag2, "only one is true",
        "both are false"
    )
)

```

if they’re not, as your code suggest, simply replace `tag1` and `tag2` with a boolean expression:

```auto
if (tag1 > 0 && tag2 > 0, "both are above 0",
    if (tag1 > 0 || tag2 > 0, "only one is above 0",
        "both are 0"
    )
)

```

Technically, `||` isn’t an `xor` operator, but if you reach that point then the check for `both are true` has already been made, which means if `a || b` returns true then only one can be true.  
The fallback then handles the `both are false` case.

---

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 7:44am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/3 "2022-07-20T07:44:42Z")

</div>

one is a boolean and one is me checking if something is greater than 0 , would that still work?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 7:46am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/4 "2022-07-20T07:46:13Z")

</div>

Yes, just mix and match. Use the boolean value of the boolean tag directly, and use your comparison for the other one.

```auto
if (tag1 && tag2 > 0, "both conditions are true",
    if (tag1 || tag2 > 0, "only one is true",
        "both are false"
    )
)

```

If it makes it clearer, you can think of it like this:

```auto
if (tag1 = true && tag2 > 0, "both conditions are true",
    if (tag1 = true || tag2 > 0, "only one is true",
        "both are false"
    )
)

```

Except you don’t need to explicitly check for truth if your tag is already a boolean.

---

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 7:55am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/5 "2022-07-20T07:55:58Z")

</div>

ah I see, because a true is a 1 right? so its just checking 1 \>0

nice, thanks for the help , I didn’t even know you could use && and ||

ill let you know if it works after it runs again

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 8:09am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/6 "2022-07-20T08:09:13Z")

</div>

Well, I guess you could technically think about true as 1, but that’s not why I write it like this.  
It’s about readability. It doesn’t make much sense with names like `tag1` and `tag2`, but with real names (if you’re following a logical naming convention) it makes things clear and simple.  
Let’s say your boolean tag is named something like `engine_started`, and your value tag is named `gear`.  
To know if you can get your car moving by stepping on the pedal, this is quite clear:

```auto
if (engine_started && gear > 0, "car moves",
    if (engine_started || gear > 0, "you're missing one step",
        "you need to turn on the engine and switch on first gear if you want to move"
    )
)

```

Now, technically, you don’t HAVE to compare `gear`’s value to 0. If it’s 0, using it in a boolean expression will return `false`, because it’s 0. You could write

```auto
if (engine_started && gear, "car moves",
    if (engine_started || gear, "you're missing one step",
        "you need to turn on the engine and switch on first gear if you want to move"
    )
)

```

if `gear` is above 0, then it will be considered true. It will work. But I find `gear > 0` brings more meaning to the code. It’s more explicit.

---

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 8:16am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/7 "2022-07-20T08:16:31Z")

</div>

its looking like its working!! , thanks again

---

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 8:20am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/8 "2022-07-20T08:20:46Z")

</div>

from the looks of it, it flickers a fault for a second during the transition

so it looks like I need to add a third condition checking that only 1 tag is on for longer then a certain period of time

any idea how I would go about that?

at least that is telling me all 3 of the current conditions are active when they should be

maybe a delay before that or check , does expression have delays?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 8:26am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/9 "2022-07-20T08:26:25Z")

</div>

I’m not sure I understand the issue…  
What flickers, and what is the transition you’re talking about ? Can I see the actual thing you’re using ?

---

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 8:28am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/10 "2022-07-20T08:28:28Z")

</div>

the issue is Tag 1 goes true and it takes about half a second before Tag 2 updates over 0

so it will show faulted during that half a second

the if statement you have is working as intended , I just didn’t think of that tiny time in between

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 20, 2022, 8:30am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/11 "2022-07-20T08:30:54Z")

</div>

You should use binEnc to combine your two tags into a single binary encoded integer. Then use case and test for 0, 1, 2, 4. Using ifs for this is overly complicated

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 8:30am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/12 "2022-07-20T08:30:55Z")

</div>

Can you show me how you’re using that expression ? It shouldn’t flicker or anything, there’s no reason any amount of time between activations would lead to a fault…

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 8:34am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/13 "2022-07-20T08:34:01Z")

</div>

I don’t find 2 simple `if`s to be more complicated than a`binEnc` and a `case` :X

---

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 8:35am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/14 "2022-07-20T08:35:30Z")

</div>

Ok so tag 1 is a solenoid and tag 2 is the output value that goes up when that solenoid is activated

if solenoid = true and output is greater than 0 then its running as intended

but i wanted to check if for some reason the solenoid comes on by itself, or there is only an output, then i have a problem I can go investigate on the machine

the flicker only happens on the way back down, the output is at 5 , so once the solenoid shuts off it takes a second for the output to go back to 0 , which is the time i get the fault

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 8:40am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/15 "2022-07-20T08:40:30Z")

</div>

I don’t see how that would cause a fault (which I understand as ‘makes the expression error out’).  
Show us (like, a screenshot or a gif) how you’re using it.

---

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 8:49am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/16 "2022-07-20T08:49:14Z")

</div>

![Expression](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2f523d655b0ebc8cb6c0f0b2ff2bf55a44539f06.jpeg)

This expression creates a status based on the 2 tags

![status](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/1/313c28813a94c11dd42d770c4ae1276707a903e8.jpeg)

which is just bound to a pump symbol’s state in perspective , so i can visually see if running stopped or faulted

the output value goes between -.03 and 5 whenever the solenoid comes on so I just used 0 as the check since its default value when its not on is below 0

the output is quick to go from -.03 above 0 because its next to it, but once its up at 5 , it takes time on the way back down

so if the solenoid turns Off the 5 is tripping the Fault check until it gets back down to 0 because it takes 1 second for it to go from 5 - 0

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 8:59am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/17 "2022-07-20T08:59:34Z")

</div>

OOOh okay I get it, when you say you get a fault, you mean it’s the status `faulted` returned by the expression !  
I thought you were getting an error while the value was coming back down to 0…

Well, I guess you could throw in timestamp checks on `{SolenoidON}`… but that gets messy real quick.

---

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [July 20, 2022, 9:03am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/18 "2022-07-20T09:03:18Z")

</div>

is there any way to delay in expressions? if it did the or check 2 seconds after the both check it wouldnt hurt anything

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 20, 2022, 9:17am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/19 "2022-07-20T09:17:58Z")

</div>

I don’t think it’s a good idea to add a delay to the evaluation itself. But I guess using an intermediate custom property on your pump symbol, and doing some timestamp comparisons to determine if the evaluation should be run, you could manage to effectively delay it…

I can’t do that now (I have my own job to attend to ;p) but if I find some time I’ll see if I can figure something out - though someone else might just come in and give you the answer in the meantime.

---

<div class="post-metadata">

**Author:** ![srija\_somisetty](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@srija\_somisetty](https://forum.inductiveautomation.com/u/srija_somisetty)\
**Post date:** [April 11, 2024, 8:57am UTC](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105/20 "2024-04-11T08:57:19Z")

</div>

I am trying to use this if condition in expression binding in ignition perspective. Where it has to return true if the tag values are in limits else false but even though the tag values are out of limits it is returning only true.

```auto
 if( ((tag1 > limit_l1) && (tag1 < limit_h1))||
     ((tag2 > limit_l2) && (tag2 < limit_h2))||
     ((tag3 > limit_l3) && (tag3 < limit_h3)) , True, False)

```

[Next page](https://forum.inductiveautomation.com/t/multiple-condition-expression-nested-if-statement/62105.md?page=2)
