Named Expressions (and derivatives like Item Types expressions) offers IIF condition. In some situations, when more values to be checked (see e.g. this discussion) it leads to nested expressions, that are hard to understand.
It would be nice to have standard switch/case statement available, that can be be used instead of nested IIF conditions.
Hi Jan,
Thanks for the idea.
As I suggested earlier, switch statement can be introduced at core EC level with syntax: switch(value, match1, result1, [match2, result2, ...], [default_value]). So that, it will be available for both Named Expression and ItemType Expression.
Can you please confirm if this approch satisfies your reuest?
Thanks!
Here is my suggestion:
Syntax:
switch(value, match1, result1, [match2, result2, ...], [default_value])
EXAMPLES
switch("Red", "Red", 1, "Blue", 2) => 1
switch("Green", "Red", 1, "Blue", 2) => null
switch("Green", "Red", 1, "Blue", 2, 3) => 3 ==> Default value
switch("Red", "Green", 1, "Red", "string") => 0
switch("Red", "Green", "string", "Red", 0) => "0.0"
Use this function to define complex if/else if/else style logic for matching values. The first match argument that equals value will return its respective result argument. If no match equals value, then either the optional default_value argument, or null, will be returned.