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›]
var gradeMap = {
"A": 1,
"B": 2,
"C": 3,
};
node.gradeMap[node.jobband]
tSQL
~CASE!~ «(field)» ~WHEN!~ ‹condition1› ~THEN!~ ‹return1› ~ELSE!~ ‹return2› ~END!~
SELECT CASE(JobBand)
WHEN "A" THEN 1
WHEN "B" THEN 2
WHEN "C" THEN 3
AS Grade
FROM EmployeesData
NB. If you omit the «field», the CASE
statement will search all fields.
CASE
WHEN MIN(Value) <= 0 THEN 0
WHEN MAX(Value) >= 100 THEN 1
END
Python
‹var expression› = {‹condition1›: ‹return1›,« condition2: return2, ...»}; ‹expression›[‹field›]
gradeMap = {
"A": 1,
"B": 2,
"C": 3,
};
gradeMap[jobBand]
NB. The above example assumes a variable has been declared for jobBand
. For more information, go to General > Variables.
Last updated
Was this helpful?