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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Jensej
Helper V
Helper V

SQL Nested CASE in DAX

Hello

 

Can someone please help to write this code in DAX. I've been trying for ages now with the switch funktion but can't get it to work. 

 

 

DECLARE @A INT
DECLARE @B INT
DECLARE @C INT
SET @A = 10
SET @B = 20
SET @C = 30


SELECT 
CASE 
WHEN @B > @C
	THEN 
		CASE 
		WHEN @B > @A 
		THEN @B+5 
		ELSE @A+5 
	END 
ELSE 
	CASE 
	WHEN @C > @A 
	THEN @C+5 
	ELSE @A+5 
	END 
END

 

2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

@Jensej

It'll be on this line.

Measure = 
VAR _A = 10
VAR _B = 20
VAR _C = 30
RETURN
SWITCH (
    TRUE(),
    _B > _C,
    SWITCH(
        TRUE(),
        _B > _A, _B + 5,
        _A + 5
    ),
    SWITCH(
        TRUE(),
        _C > _A, _C + 5,
        _A + 5
    )
)

View solution in original post

You could also do it with an IF

Measure2 = 
VAR _A = 10
VAR _B = 20
VAR _C = 30
RETURN
IF ( _B > _C,
    IF(_B > _A, _B + 5, _A + 5),
    IF(_C > _A, _C + 5, _A + 5)
)

View solution in original post

4 REPLIES 4
jdbuchanan71
Super User
Super User

@Jensej

It'll be on this line.

Measure = 
VAR _A = 10
VAR _B = 20
VAR _C = 30
RETURN
SWITCH (
    TRUE(),
    _B > _C,
    SWITCH(
        TRUE(),
        _B > _A, _B + 5,
        _A + 5
    ),
    SWITCH(
        TRUE(),
        _C > _A, _C + 5,
        _A + 5
    )
)

You could also do it with an IF

Measure2 = 
VAR _A = 10
VAR _B = 20
VAR _C = 30
RETURN
IF ( _B > _C,
    IF(_B > _A, _B + 5, _A + 5),
    IF(_C > _A, _C + 5, _A + 5)
)
amitchandak
Super User
Super User

@Jensej ,

Switch ( True() ,

//condition //or another Switch ,

//condition //or another Switch ,

//else condition

)

refer

https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Like this? 

 

Switch ( True() , B > C, Switch ( True(), B > A, B+5, A+5) , Switch ( True() C > A, C+5, A+5)

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.