Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
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
Solved! Go to Solution.
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)
)
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)
)
@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/
Like this?
Switch ( True() , B > C, Switch ( True(), B > A, B+5, A+5) , Switch ( True() C > A, C+5, A+5)
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.
| User | Count |
|---|---|
| 21 | |
| 18 | |
| 18 | |
| 17 | |
| 13 |
| User | Count |
|---|---|
| 61 | |
| 53 | |
| 47 | |
| 40 | |
| 38 |