Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
If I have individual values that I am looking for in a SWITCH statement (for example Dept = 1, 2, 3 or 4; no complex or multiple conditions), is there any downside to using
SWITCH(Dept, 1, Val1, 2, Val2, 3, Val3, 4, Val4, 0)
vs
SWITCH( TRUE(), Dept = 1, Val1, Dept = 2, Val2, ...)
Thanks,
David
Solved! Go to Solution.
For your scenario,since you only have individual values, it is better and easier to use the first case though it is no difference to the result with two ways.
SWITCH has two types of structure.
The first usage of the SWITCH function has the following structure:
SWITCH(expression, value1, result1, value2, result2, : : else )
expression is any DAX expression that returns a single scalar value (number, string, or date), where the expression is to be evaluated multiple times (for each row/context).
value1 is a constant value to be matched with the evaluated result of expression.
result1 is any scalar expression (i.e. one that returns a scalar value) to be evaluated if the results of expression match the corresponding value1.
else is any scalar expression to be evaluated if the result of expression doesn’t match any of the value arguments
expression, value1, and result1 are the only mandatory parameters in SWITCH. If the formula contains multiple value/result pairs, then the data types of result1, result2…resultn must be the same. In addition, if you include an else expression, the expression must evaluate to the same data type as result.
The second usage of the SWITCH function has the following structure:
SWITCH(TRUE(), booleanexpression1, result1, booleanexpression2, result2, : : else )
where TRUE() is a DAX function, and booleanexpression1,booleanexpression2,…are any valid Boolean expressions (i.e. returns True or False). The first booleanexpression that evaluates to True will return the corresponding result as the formula result.
Best Regards
Maggie
hi
switch function -- i couldnt link the original table values, they dont appear.. please help..
switch(true(),selected value="abc",[ def]----> this def value i cannot get it.. please help..
thanks
Giri
For your scenario,since you only have individual values, it is better and easier to use the first case though it is no difference to the result with two ways.
SWITCH has two types of structure.
The first usage of the SWITCH function has the following structure:
SWITCH(expression, value1, result1, value2, result2, : : else )
expression is any DAX expression that returns a single scalar value (number, string, or date), where the expression is to be evaluated multiple times (for each row/context).
value1 is a constant value to be matched with the evaluated result of expression.
result1 is any scalar expression (i.e. one that returns a scalar value) to be evaluated if the results of expression match the corresponding value1.
else is any scalar expression to be evaluated if the result of expression doesn’t match any of the value arguments
expression, value1, and result1 are the only mandatory parameters in SWITCH. If the formula contains multiple value/result pairs, then the data types of result1, result2…resultn must be the same. In addition, if you include an else expression, the expression must evaluate to the same data type as result.
The second usage of the SWITCH function has the following structure:
SWITCH(TRUE(), booleanexpression1, result1, booleanexpression2, result2, : : else )
where TRUE() is a DAX function, and booleanexpression1,booleanexpression2,…are any valid Boolean expressions (i.e. returns True or False). The first booleanexpression that evaluates to True will return the corresponding result as the formula result.
Best Regards
Maggie
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
87 | |
64 |