DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

IIF behavior in calculate function

Solved!
Go to solution

Hi,

 

So I've got a simple formula like that:

Call Calculate("ch(""result"")=IIF(ch(""Xpct"")<50,0,ch(""Y"")/(ch(""Xpct"")/100))")

 

The Xpct channel can and will have values at exact zero. This is the reason I use the IIF condition: when Xpct is below 50%, I would like to have the resulting channel to be at zero.

 

As it turns out, the resulting channel still has NoValues when Xpct is at zero, see screenshot.

 

Is it normal? What should I do to avoid that?

 

Problem reproduced on DIAdem 2017 and 2020. We are in the process of installing and evaluating DIAdem 2023, but that takes time. And I don't think it will solve this "feature".

 

Thanks,

Jacques

 

DJacques_0-1684270524307.png

 

0 Kudos
Message 1 of 4
(1,428 Views)
Solution
Accepted by topic author DJacques

If you have like "25" in Xpct it will produce 0.  My guess it runs both calculations and combines them based on your criteria, but when it is zero, you end up dividing by zero, and any combination will result in NoValue

 

ch(""Y"")/(ch(""Xpct"")/100) = 1/0/100 = NoValue

you can run this right after:

Call ChnNovHandle("[1]/result", "[1]/result", "SetValue", "XY", True, True, 0)
0 Kudos
Message 2 of 4
(1,390 Views)

Thanks for the reply! I thought about using the NoValue handling function, but I was hoping to find a more elegant way, i.e. having the IIF function doing what I would like to do...

 

Thanks!

0 Kudos
Message 3 of 4
(1,359 Views)

I have a one line solution, though it involves evaluation a nested IIF so not sure about performance (if that matters):

 

ch("[1]/result") = IIF(IIF(ch("[1]/Xpct")=0,1,ch("[1]/Xpct"))<50,0,ch("[1]/Y")/IIF(ch("[1]/Xpct")=0,1,ch("[1]/Xpct")/100))
0 Kudos
Message 4 of 4
(1,331 Views)