Article

DAX Language - SWITCH Function

DAX Language - SWITCH Function


A.Baddane | Posted on April 07, 21

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
Add to favorite
Categories
Recent Posts
Filter column based on a list in Power Query
A.Baddane | April 05, 23

Sometimes when you work within power query, you need to filt...Read More


Use HTML in Power BI - Part 2
A.Baddane | July 05, 22

In the first blog post about using HTML in Power BI Desktop,...Read More


Use HTML in Power BI
A.Baddane | Feb. 21, 22

In this blog post, I will show you how to use HTML to create...Read More


Covid-19 Report
A.Baddane | Nov. 23, 21

The COVID-19 pandemic, also known as the coronavirus pandemi...Read More