How to use AND in Case and Switch statements

I wonder is it possible to use AND in "Case" or "Switch" statement. I am keep getting error.

I need to do switch if value of two tags turns to 1 and 6:
for example:
"when MachineMode=1 and tag2=6 turns defined tag to 3 etc.
see below
Switch ({[.]../MachineStatus/MachineMode},1 && tag2=6,0,2,3,4,5,
3,
1,
1,
2,
1,
1,
1)),0)

No, you cannot. Switch operates on a single input, and the && operator automatically returns a boolean, so you'll only have two possible inputs to your switch (true and false).
Try to write out the truth table you're aiming for.
When MachineMode is 1 and Tag2 is 6, the output is what?
When MachineMode is not 1 and Tag2 is 6, the output is what?
When MachineMode is 1 and Tag2 is not 6, the output is what?
When MachineMode is not 1 and Tag2 is not 6, the output is what?

1 Like

A simple solution:

case(tag2 * 100 + {[.]../MachineStatus/MachineMode},
    0,   "black",
    2,   "brown",
    100, "gray",
    102, "yellow",
    206, "blue",
    "white"          // default
)

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

1 Like