我想知道如何更改此 DAX 代码,以使用 Case Switch 而不是 IF
IF(VALUES(Rankings\[Attribute\]) = "AERIAL DUELS WON %", format(SUM(Rankings\[Value\]),"##%"),
IF(VALUES(Rankings\[Attribute\]) = "CROSSES",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "Crossing%",FORMAT(SUM(Rankings\[Value\]),"##%"),
IF(VALUES(Rankings\[Attribute\]) = "FORWARD PASSES %",FORMAT(SUM(Rankings\[Value\]),"##%"),
IF(VALUES(Rankings\[Attribute\]) = "FOULS COMMITTED",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "GOALS",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "GOALS CONCEDED",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "GROUND DUELS WON %",FORMAT(SUM(Rankings\[Value\]),"##%"),
IF(VALUES(Rankings\[Attribute\]) = "NON-PENALTY SHOT CONVERSION RATE %",FORMAT(SUM(Rankings\[Value\]),"##%"),
IF(VALUES(Rankings\[Attribute\]) = "NON-PENALTY SHOTS",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "OWN HALF BALL LOSS",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "PASS FORWARD IN FINAL 3RD %",FORMAT(SUM(Rankings\[Value\]),"##%"),
IF(VALUES(Rankings\[Attribute\]) = "PASSES",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "POSSESSION REGAINS IN OPPO HALF TOTAL",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "Possession%",FORMAT(SUM(Rankings\[Value\]),"##%"),
IF(VALUES(Rankings\[Attribute\]) = "RED CARDS",IF(SUM(Rankings\[Value\]) \>0, FORMAT(SUM(Rankings\[Value\]),"##"),0),
IF(VALUES(Rankings\[Attribute\]) = "SHOTS INSIDE BOX",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "SHOTS ON TARGET %",FORMAT(SUM(Rankings\[Value\]),"##%"),
IF(VALUES(Rankings\[Attribute\]) = "SHOTS OUTSIDE BOX",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "Successful Box Cross",FORMAT(SUM(Rankings\[Value\]),"##"),
IF(VALUES(Rankings\[Attribute\]) = "YELLOW CARDS",FORMAT(SUM(Rankings\[Value\]),"##")
)))))))))))))))))))))`
我需要更改格式才能使用 CASE SWITCH
您可以使用此模式:
SWITCH(TRUE()
, Condition1, Output1
, Condition2, Output2
, Condition3, Output3
, Default
)
示例:
SWITCH(TRUE()
, VALUES(Rankings[Attribute]) = "AERIAL DUELS WON %", format(SUM(Rankings[Value]),"##%")
, VALUES(Rankings[Attribute]) = "CROSSES",FORMAT(SUM(Rankings[Value]),"##")
, ...
)