DAX Logical - SWITCH function



Description

Evaluates an expression against a list of values and returns one of multiple possible result expressions.

Syntax

SWITCH (
   <expression>, <value>, <result>, [<value>, <result>] …, [<else>]
) 

Parameters

Sr.No. Parameter & Description
1

expression

Any DAX expression that returns a single scalar value, where the expression is to be evaluated multiple times for each row/context.

2

value

A constant value to be matched with the results of expression.

3

result

Any scalar expression to be evaluated, if the results of expression match the corresponding value.

4

else

Optional.

Any scalar expression to be evaluated, if the result of expression doesn't match any of the value arguments.

Return Value

A scalar value coming from one of the result expressions, if there was a match with value, or from the else expression, if there was no match with any value.

Remarks

All the result expressions and the else expression must be of the same data type.

Example

= SWITCH (
   [Week Day], 1, "Sunday", 2, "Monday", 3, "Tuesday", 4, "Wednesday", 
      5, "Thursday", 6, "Friday", 7, "Saturday", "Unknown"
) 

This DAX formula returns a calculated column with the names of the Week Day values.

dax_functions_logical.htm
Advertisements