Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
Is it possible to have a switch statement in an expression????
Actually I have a scenario in which
if(var=1)
set analysis1 getting execuited;
if(var=2)
set analysis2 getting execuited;
if(Var=3)
set analysis3 getting execuited;
else
default value;
this set of conditional stmt is an expression in a straight table chart I need to replace this conditional stmt with a switch statement or else any other apart from conditional statement....Can any one help me regarding the above
Thanks,
Kiruthiga
Hi,
why don't you use anidated if? They work fine in expressions. For your example:
if(var=1, analysis1,if(var=2, analysis2, if(var=3, analysis3, defaultvalue)))
The closest equivalent of the switch statement is probably pick(match()). For instance:
pick(1+match(var,1,2,3),defaultvalue,analysis1,analysis2,analysis3)
Though in your case, with ascending whole number values, you may not need the match():
pick(1+var,defaultvalue,analysis1,analysis2,analysis3)
But I think nesting if() statements is more clear and more easily maintained if you can afford the overhead of repeated reference to the variable. I would typically put one per line, giving what I think is the clearest connection between the value and the result:
if(var=1,analysis1
,if(var=2,analysis2
,if(var=3,analysis3
,defaultvalue)))
Grrr... the new forum won't let me put a space in front of the if() on the first line to line them up properly.