Expression Statement if not 0

I am trying to write an expression statement that is taking 2 machines production rate minus there goal. The problem is that when one of the machines is off, its production rate is 0, which skews the numbers. This is my current statement:

{[default]E289/E289/Analytics/Current/Shift Production at Current}+{[default]E293/E293/Analytics/Current/Shift Production at Current})-({[default]E231/E231/Analytics/Current/Shift Goal at Current}+{[default]E233/E233/Analytics/Current/Shift Goal at Current}

Is there some way that I could exclude a machines "Shift Goal at Current" number if the "Shift Production at Current" number is 0?

You can use the if() expression to check the value and return one of two equations depending on the result.

if({Shift Production at Current} > 0, equation including machine, equation excluding machine)

https://docs.inductiveautomation.com/display/DOC81/if

Your post mentions two machines but your post seems to reference four machines, E231, E233, E289 and E293. Also you are missing the opening and closing ( ). Anyway, the full expression would be something like:

if(
    {[default]E289/E289/Analytics/Current/Shift Production at Current} > 0,
    {[default]E289/E289/Analytics/Current/Shift Production at Current}
    + {[default]E231/E231/Analytics/Current/Shift Goal at Current},
    0
)
+
if(
    {[default]E293/E293/Analytics/Current/Shift Production at Current} > 0,
    {[default]E293/E293/Analytics/Current/Shift Production at Current}
    - [default]E233/E233/Analytics/Current/Shift Goal at Current},
    0
)

Tips:

  • Expressions generally ignore linebreaks, tabs and additional spaces so you can wrap your expressions as I have shown for readability.
  • Add a space each side of the mathematical operators to let some air into your expressions (and equations in scripts). It makes them easier to read.
2 Likes

I tried this and it looks right, but I am getting this error
image
and it is referring to the > symbol

+(if {[default]E236/E236/Analytics/Current/Shift Production at Current} > 0,{[default]E236/E236/Analytics/Current/Shift Goal at Current},0)

Sorry I fixed it, I missed a parentheses..

1 Like