Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have a dax if statement that shows a letter grade according to the scored points for the vendor. The slicer has a list of vendors. The table has columns for month, points scored and grade. Table displays data correctly when one vendor is selected but doesn't display letter grades when Select All is selected on the vendor slicer. The Statement that has grades is below:
Solved! Go to Solution.
You can write that more succinctly with a SWITCH.
Avg_EDI_Grade =
VAR Avg = Scorecard[Avg_EDI_Points]
RETURN
SWITCH (
TRUE (),
Avg <= 0, "F",
Avg <= 1, "D",
Avg <= 2, "C",
Avg <= 3, "B",
Avg <= 4, "A"
)
I actually had to rework that cause I found it wasn't working as I thought. Solution was:
Avg_EDI_Grade = VAR AvgGrd = Scorecard[Avg_EDI_Points] RETURN SWITCH ( TRUE (), AvgGrd <= 0.5, "F", AvgGrd >0.5 && AvgGrd <= 1.5, "D", AvgGrd > 1.5 && AvgGrd <= 2.5, "C", AvgGrd > 2.5 && AvgGrd <= 3.5, "B", AvgGrd >3.5 && AvgGrd <= 4, "A")
You can still use the sequencing of the switch arguments to prevent needing to check both sides.
Avg_EDI_Grade =
VAR AvgGrd = Scorecard[Avg_EDI_Points]
RETURN
SWITCH (
TRUE (),
AvgGrd <= 0.5, "F",
AvgGrd <= 1.5, "D",
AvgGrd <= 2.5, "C",
AvgGrd <= 3.5, "B",
AvgGrd <= 4, "A"
)
If you have multiple vendors selected with different grades, how is it supposed to work? Some kind of average or weighted average? What if the average is 3.5? Is that an A or B?
Posting sample data and the desired result would help you get an answer.
https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523
I thought formatting the columns as whole numbers get around that but I see what you mean.
But I'm getting an error: Too few arguments were passed to the IF function. The minimum argument count for the function is 2.
You can write that more succinctly with a SWITCH.
Avg_EDI_Grade =
VAR Avg = Scorecard[Avg_EDI_Points]
RETURN
SWITCH (
TRUE (),
Avg <= 0, "F",
Avg <= 1, "D",
Avg <= 2, "C",
Avg <= 3, "B",
Avg <= 4, "A"
)
Thanks. Thanks worked great. Youre help was much appreciated.
I actually had to rework that cause I found it wasn't working as I thought. Solution was:
Avg_EDI_Grade = VAR AvgGrd = Scorecard[Avg_EDI_Points] RETURN SWITCH ( TRUE (), AvgGrd <= 0.5, "F", AvgGrd >0.5 && AvgGrd <= 1.5, "D", AvgGrd > 1.5 && AvgGrd <= 2.5, "C", AvgGrd > 2.5 && AvgGrd <= 3.5, "B", AvgGrd >3.5 && AvgGrd <= 4, "A")
You can still use the sequencing of the switch arguments to prevent needing to check both sides.
Avg_EDI_Grade =
VAR AvgGrd = Scorecard[Avg_EDI_Points]
RETURN
SWITCH (
TRUE (),
AvgGrd <= 0.5, "F",
AvgGrd <= 1.5, "D",
AvgGrd <= 2.5, "C",
AvgGrd <= 3.5, "B",
AvgGrd <= 4, "A"
)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
44 | |
25 | |
19 | |
16 | |
8 |
User | Count |
---|---|
70 | |
48 | |
45 | |
19 | |
16 |