Case / Switch

Excel

Excel doesn't support a specific case function but instead use an IF...ELSE statement =~IF!~(‹logical_test1›, ‹when_true1›, ~IF!~(‹logical_test2›, ‹when_true2›, ‹when_false2›))

=IF(C10 = "A", 1, IF(C10 = "B", 2, IF(A1 = "C", 3,0)))

Tableau

~CASE!~ ‹field› ~WHEN!~ ‹condition1› ~THEN!~ ‹return1› «WHEN condition2 THEN return2 ... » ~ELSE!~ ‹returnN› ~END.~

CASE [Job Band] 
  WHEN "A" THEN 1 
  WHEN "B" THEN 2 
  WHEN "C" THEN 3 
END

NB. Each WHEN tests the actual string provided and compares it to the value of the target field; it does not allow logical tests e.g. WHEN > 10 .... For this, use an IF...ELSE statement.

Alteryx

~SWITCH!~(‹field›, ‹default_result›, ‹condition1›, ‹return1›«, condition2, return2, ...»)

SWITCH([Job Band], 0, 
  "A", 1, 
  "B", 2, 
  "C", 3
)

OrgVue

‹var expression› = {‹condition1›: ‹return1›«, condition2: return2, ... »}; ‹expression›[‹node.field›]

tSQL

~CASE!~ «(field)» ~WHEN!~ ‹condition1› ~THEN!~ ‹return1› ~ELSE!~ ‹return2› ~END!~

NB. If you omit the «field», the CASE statement will search all fields.

Python

‹var expression› = {‹condition1›: ‹return1›,« condition2: return2, ...»}; ‹expression›[‹field›]

NB. The above example assumes a variable has been declared for jobBand. For more information, go to General > Variables.

Last updated

Was this helpful?