Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
domtrump
Helper II
Helper II

CASE Statement replacement for DAX

I don't know when/if the CASE syntax will ever be a part of DAX but I was just wondering if there is a better approach than nested, upon nested, upon nested inline IF syntax? Sure, for very simple things like replacing numeric codes with lables, SWITCH works nicely, but when there are calculations involved, the IF's get very hard to read. Is there some other syntax I'm not aware of? I've seen some examples of making a new column in PQ using an If Then Else construct. Is that the better way to go? If so, what would be the PQ syntax to replace SQL Server's 

CASE WHEN x THEN y ELSE z END ? 

1 ACCEPTED SOLUTION
djurecicK2
Super User
Super User

Hi @domtrump ,

 I think Switch is what a lot of people use. If the calculations are cluttering up the formula, you might consider using variables to separate those from the switch statement- something like below:

 

Measure =
VAR ComplexCondition1 = longcomplexformula1
VAR ComplexResult2 = longcomplexformula2
RETURN
    SWITCH ( TRUE (), [ComplexCondition1], [ComplexResult1] )

etc...

View solution in original post

2 REPLIES 2
djurecicK2
Super User
Super User

Hi @domtrump ,

 I think Switch is what a lot of people use. If the calculations are cluttering up the formula, you might consider using variables to separate those from the switch statement- something like below:

 

Measure =
VAR ComplexCondition1 = longcomplexformula1
VAR ComplexResult2 = longcomplexformula2
RETURN
    SWITCH ( TRUE (), [ComplexCondition1], [ComplexResult1] )

etc...

I did NOT know you could use FORMULAS in SWITCH! Awesome. Thanks so much. -Dom

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.