Article

DAX Language - SWITCH Function


A-Badde | Posted on April 07, 20

SWITCH Function

 Description:

The SWITCH function evaluates an expression and returns different results depending on the value of the expression.

 Return Value:

SWITCH returns a scalar value coming from one of the Result expressions.

 Syntax:

SWITCH( <expression> 
        ,<value>, <result>[
        , <value>, <result>]…[
        , <else>]
      ) 
  • Description of the parameters:

 

PARAMETER

DESCRIPTION

expression

DAX expression to be evaluated, that returns a single scalar value

value

A constant value to be matched with the results of expression

result

Scalar expression to be evaluated if the results of expression match the corresponding value

else

If there are no matching values the else value is returned

 

 Example:

 

  The following example creates a calculated column of quarter names

Quarter Name = SWITCH('Calendar'[QuarterOfYear]
                        ,1,"Quarter 1"
                        ,2,"Quarter 2"
                        ,3,"Quarter 3"
                        ,4,"Quarter 4"
                        ,"Unknown quarter number"
                    )

  We can use SWITCH function to replace the nested IF functions like in the example above.

 

Related Video:

 

 


(0) Comments

There is no comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Add to favorite
Categories
Recent Posts
DAX Language - CONTAINS Function
A-Badde | May 09, 20

The CONTAINS function returns a boolean value, TRUE if each ...Read More


DAX Language - RANKX Function
A-Badde | May 05, 20

The RANKX function returns a single integer value that repre...Read More


DAX Language - AND and OR Functions
A-Badde | April 10, 20

AND/OR functions check whether all arguments are TRUE or one...Read More


DAX Language - Variables in DAX
A-Badde | April 10, 20

Use Var keyword to store the result of an expression as a na...Read More