New instruction SWITCH CASE

it would be useful to have, in extended espression syntax, the new instrucion switch / case like in C#
switch (caseSwitch)
{
case 1:
Console.WriteLine(“Case 1”);
break;
case 2:
Console.WriteLine(“Case 2”);
break;
default:
Console.WriteLine(“Default case”);
break;
}

1 Like

We thought about this, but whatever idea for SWITCH/CASE syntax we came up with was only marginally better than what is already available:

IF case1 THEN ....
ELSE
IF case2 THEN ....
ELSE
...

Functional syntax (such as in F#) is pretty convenient, but I’m not sure if it’s sufficiently user friendly:

match A with
| case1 -> expression1
| case2 -> expresison2
| _ -> defaultExpression

The first choice is definitely userflendy and can be fine when you have a few IF... THEN (maximum 10).
But a more synthetic syntax like the second (F#) might be useful when dealing with 100 or more Choiches.
For example, I felt that I had to make several replacements (about fifty) and, not knowing yet about the beta extended espression syntax, I had nested 50 IF one inside the other ... IF (a=1, x="uao", (IF a=2, x="wow", ... ))
So the syntax like F# is interesting:
match A with
| case1 -> expression1
| case2 -> expresison2
| _ -> defaultExpression

I was also looking for a CASE OF expression (Similar to the one in SQL) for calculating a column.
E.g. Translating a Code Number to a Code Description.
Having nested IF expressions becomes cumbersome if there are many conditions.
I guess that one could create a lookup table and then do a merge or lookup - but that would require an extra step.

Hi,
What would be the added value of a SWITCH/CASE function compare to the Rules transformation ?
Have you got a use case in mind ?
Regards

The RULE Function does also work if there also was a feature in it to decide where to place the new calculated column. The RULE action places the resulting column at the right end, and I have to use one action step more to move it to where I need it.

The use case is to translate a column containing category codes (e.g. from er ERP system) into human understandable text.
Example:
Code value: 14 -> Code description: "Abc"
Code value: 15 -> Code description: "Def"
Code value: 16 -> Code description: "Ghi" ....

That's a case for the "Lookup" action + lookup table created using the "Create list" action.

SWITCH/CASE would be a worse solution, because it's imperative while using a lookup table is declarative.

I agree that having the "Position" option on the Rule transformation would be nice.

I'm currently starting a project with a lot of surrogate keys to define (SAP...) this is why I'm interrested with your feedback.
Can't you get the expected results with the "Lookup" transformation ?

I thought you were looking for a kind of "Rule Case" transformation.
The same structure than the Rule transformation but only one "if" formula and several cases options
IF : x + y
CASE : 100
then : A
CASE : 200
then : B
CASE : 300
then : C
ELSE : empty

One of the main quality of EM is that it can display very complex transformations in an intuitive way and I appreciate Dmitry to stick to this core concept even if it implies to overdecompose some steps sometime.

Regards

I will look into the Create List action instead of doing an import - that makes sense.
It would thou still require me using an extra action step in the project.

I was primarily looking for a way to avoid making a to big nested IF expression.
Both RULE & LOOKUP can do the trick but all require an extra step.
Adding the Position option to RULE would be fine.