# Expression for checking between two values

**URL:** <https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 25, 2026, 1:37am UTC](https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682 "2026-05-25T01:37:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [May 25, 2026, 1:37am UTC](https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682/1 "2026-05-25T01:37:51Z")

</div>

I am using an expression transform, to consolidate the simple math for a status tag.

The expression below is always 0, even though the value is 50 and the ideal min is 60. I was assuming that since that's false, it would jump to the next if. before I change this to a script transform, any suggestions on why the expression isn't working?

Bonus points if you have me get off of the awful if statement below. thanks!

```python
if( {view.custom.ideal_min} <= {value} <= {view.custom.ideal_max}, 0,
	if( {view.custom.acceptable_min} <= {value} <= {view.custom.ideal_min}, -1,
		if( {value} <= {view.custom.acceptable_min}, -2,
			if( {view.custom.ideal_max} <= {value} <= {view.custom.acceptable_max}, 1,
				if( {value} >= {view.custom.acceptable_max}, 2, 999)
			)
		)
	)
)

```

---

<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:** [May 25, 2026, 2:12am UTC](https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682/2 "2026-05-25T02:12:40Z")

</div>

I don't recall expression syntax supporting chained comparisons.

---

<div class="post-metadata">

**Author:** ![danielps1818](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@danielps1818](https://forum.inductiveautomation.com/u/danielps1818)\
**Post date:** [May 25, 2026, 8:12am UTC](https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682/3 "2026-05-25T08:12:09Z")

</div>

Your code but working:

```python
if(
    and({view.custom.ideal_min} <= {value}, {value} <= {view.custom.ideal_max}), 0,
    if( 
        and({view.custom.acceptable_min} <= {value}, {value} <= {view.custom.ideal_min}), -1,
        if( 
            {value} <= {view.custom.acceptable_min}, -2,
            if( 
                and({view.custom.ideal_max} <= {value}, {value} <= {view.custom.acceptable_max}), 1,
                if( 
                    {value} >= {view.custom.acceptable_max}, 2, 
                    999
                )
            )
        )
    )
)

```

or in a simpler way:

```python
if({value} <= {view.custom.acceptable_min}, -2,
    if({value} <= {view.custom.ideal_min}, -1,
        if({value} <= {view.custom.ideal_max}, 0,
            if({value} <= {view.custom.acceptable_max}, 1,
                if({value} >= {view.custom.acceptable_max}, 2, 999)
            )
        )
    )
)

```

_Note: Hadn't tested, make sure is correct._

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 25, 2026, 2:08pm UTC](https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682/4 "2026-05-25T14:08:56Z")

</div>

A `CASE` expression is often times easier on the eyes:

```python
case(
	true,
	{value} <= {view.custom.acceptable_min},	-2,
	{value} <= {view.custom.ideal_min}, -1,
	{value} <= {view.custom.ideal_max}, 0,
	{value} <= {view.custom.acceptable_max}, 1,
	2) // # 999 doesn't seem reachable, so I've omitted it

```

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [May 25, 2026, 2:31pm UTC](https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682/5 "2026-05-25T14:31:10Z")

</div>

i like the case/switch better but I wasn't sure if you could put expressions in the case. thanks, I'll test it out.

---

<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:** [May 25, 2026, 3:15pm UTC](https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682/6 "2026-05-25T15:15:27Z")

</div>

> [@danielps1818](#):
>
> ```python
> if({value} <= {view.custom.acceptable_min}, -2,
> if({value} <= {view.custom.ideal_min}, -1,
> if({value} <= {view.custom.ideal_max}, 0,
> if({value} <= {view.custom.acceptable_max}, 1,
> if({value} >= {view.custom.acceptable_max}, 2, 999)
> )
> )
> )
> )
> 
> ```

If you do ever use nested ifs though, nesting them with indents is woeful to read. Just stick them all at the start

```python
if({value} <= {view.custom.acceptable_min}, -2,

if({value} <= {view.custom.ideal_min}, -1,

if({value} <= {view.custom.ideal_max}, 0,

if({value} <= {view.custom.acceptable_max}, 1,

if({value} >= {view.custom.acceptable_max}, 2, 999

))))) 

```

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [May 25, 2026, 5:49pm UTC](https://forum.inductiveautomation.com/t/expression-for-checking-between-two-values/115682/7 "2026-05-25T17:49:57Z")

</div>

That's much cleaner to read! thanks
