Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi!
I would like to know, how can I change this DAX Code ... to use Switch Case instead of IFs
Solved! Go to Solution.
@AGaribay7 Try
SEASON TOTAL =
SWITCH(
TRUE(),
VALUES(Rankings[Attribute]) = "AERIAL DUELS WON %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "CROSSES", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "Crossing%", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "FORWARD PASSES %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "FOULS COMMITTED", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "GOALS", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "GOALS CONCEDED", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "GROUND DUELS WON %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "NON-PENALTY SHOT CONVERSION RATE %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "NON-PENALTY SHOTS", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "OWN HALF BALL LOSS", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "PASS FORWARD IN FINAL 3RD %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "PASSES", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "POSSESSION REGAINS IN OPPO HALF TOTAL", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "Possession%", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "RED CARDS", IF(SUM(Rankings[Value]) > 0, FORMAT(SUM(Rankings[Value]),"##"), 0),
VALUES(Rankings[Attribute]) = "SHOTS INSIDE BOX", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "SHOTS ON TARGET %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "SHOTS OUTSIDE BOX", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "Successful Box Cross", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "YELLOW CARDS", FORMAT(SUM(Rankings[Value]),"##"),
BLANK() -- Default case if no condition matches
)
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
@AGaribay7 Try
SEASON TOTAL =
SWITCH(
TRUE(),
VALUES(Rankings[Attribute]) = "AERIAL DUELS WON %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "CROSSES", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "Crossing%", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "FORWARD PASSES %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "FOULS COMMITTED", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "GOALS", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "GOALS CONCEDED", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "GROUND DUELS WON %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "NON-PENALTY SHOT CONVERSION RATE %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "NON-PENALTY SHOTS", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "OWN HALF BALL LOSS", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "PASS FORWARD IN FINAL 3RD %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "PASSES", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "POSSESSION REGAINS IN OPPO HALF TOTAL", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "Possession%", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "RED CARDS", IF(SUM(Rankings[Value]) > 0, FORMAT(SUM(Rankings[Value]),"##"), 0),
VALUES(Rankings[Attribute]) = "SHOTS INSIDE BOX", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "SHOTS ON TARGET %", FORMAT(SUM(Rankings[Value]),"##%"),
VALUES(Rankings[Attribute]) = "SHOTS OUTSIDE BOX", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "Successful Box Cross", FORMAT(SUM(Rankings[Value]),"##"),
VALUES(Rankings[Attribute]) = "YELLOW CARDS", FORMAT(SUM(Rankings[Value]),"##"),
BLANK() -- Default case if no condition matches
)
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
Hi,
Try the following code:
Note: this will only make the code prettier, there is no performance benefit.
SEASON TOTAL = SWITCH(TRUE(),
VALUES(Rankings[Attribute]) in {
"AERIAL DUELS WON %",
"Crossing%",
"FORWARD PASSES %",
"GROUND DUELS WON %",
"NON-PENALTY SHOT CONVERSION RATE %",
"Possession%",
"SHOTS ON TARGET %"}, format(SUM(Rankings[Value]),"##%"),
format(SUM(Rankings[Value]),"##")
)
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
12 | |
10 | |
6 |