# Getting result of if statements in Expressions

**URL:** <https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305>\
**Category:** Ignition\
**Created:** [November 6, 2024, 8:11pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305 "2024-11-06T20:11:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [November 6, 2024, 8:11pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305/1 "2024-11-06T20:11:39Z")

</div>

I'm using ignition 8.1.43

I have an expression tag that I have several nested if statements working together to give me a numerical response. I've hit a point where I need to take the numerical response of those if statements and put it into another if statement. to either divide by 1,000 or 10,000

I certainly _could_ put this at the top of my nest if statements, but then I would have all that logic repeated twice for each branch of the if statement. Any time I changed one line I would have to go to the opposing part of the if statement and made sure I changed it there as well.

Is there anyway to put an if statement AFTER a completed statement in an expression tag and have it reference the value of the first statement? Here's an example of what I mean:

```python
If (1=1
	, 5000
	, 6000
	)
If (theSky=Blue
	, {returnedValue}/1000
	, {returnedValue}/10000
)

```

So that second if statement is using the output of the first one. Is that possible?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 6, 2024, 8:13pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305/2 "2024-11-06T20:13:23Z")

</div>

No, not directly.  
The simplest solution is to use an intermediate expression tag/custom property/whatever, to hold the first expression.

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [November 6, 2024, 8:17pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305/3 "2024-11-06T20:17:22Z")

</div>

Thanks, I'll do that then!

---

<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:** [November 6, 2024, 9:09pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305/4 "2024-11-06T21:09:27Z")

</div>

> [@abishur](#):
>
> Is that possible?

Yes, with the Integration Toolkit module's [transform()](https://www.automation-pros.com/toolkit/doc/utility.html#transform) & [value()](https://www.automation-pros.com/toolkit/doc/utility.html#value) functions.

Your scenario is precisely the kind of task those exist to solve.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 6, 2024, 9:34pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305/5 "2024-11-06T21:34:55Z")

</div>

Based on @paul-griffith's solution to a similar problem this week (which he's forgotten already), [https://forum.inductiveautomation.com/t/how-to-transform-some-tags-into-1-tag-easily/98195/8:](https://forum.inductiveautomation.com/t/how-to-transform-some-tags-into-1-tag-easily/98195/8:)

```python
case (
    stringFormat("%d.%d", 1 = 1, theSky = "Blue"), 
    "0.0", 5000,
    "1.0", 6000,
    "0.1", {returnedValue}/1000,
    "1.1", {returnedValue}/10000,
    null
)

```

I haven't tested it.

---

<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:** [November 6, 2024, 9:54pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305/6 "2024-11-06T21:54:57Z")

</div>

> [@Transistor](#):
>
> tested

Might want to look closer.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 6, 2024, 10:53pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305/7 "2024-11-06T22:53:30Z")

</div>

Eh. This does, technically, work, but I would argue obscures the logic and what your actual _intent_ is much more than an intermediate tag/custom property/whatever _with a useful name_.

Phil's solution in the integration toolkit is solid too, but I'd (personally) favor a name based approach if we ever did anything like this first party, as in some kind of variable binding syntax, but the exact details of that are very fuzzy and demand is pretty low.

---

<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:** [November 6, 2024, 11:27pm UTC](https://forum.inductiveautomation.com/t/getting-result-of-if-statements-in-expressions/98305/8 "2024-11-06T23:27:22Z")

</div>

> [@paul-griffith](#):
>
> favor a name based approach

I have a number of thoughts swirling.....

.....but they'll have to wait for after my v8.3 module updates.
