The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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"
)
User | Count |
---|---|
12 | |
9 | |
6 | |
6 | |
6 |
User | Count |
---|---|
24 | |
14 | |
14 | |
9 | |
7 |