Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

If statement doesn't work with Slicer Select All

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:

Avg_EDI_Grade = IF(Scorecard[Avg_EDI_Points]=4, "A", IF(Scorecard[Avg_EDI_Points]=3, "B", IF(Scorecard[Avg_EDI_Points]=2, "C", IF(Scorecard[Avg_EDI_Points]=1, "D", IF(Scorecard[Avg_EDI_Points]=0, "F")))))
 
Help will be much appreciated.
3 ACCEPTED SOLUTIONS

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"
    )

 

View solution in original post

Anonymous
Not applicable

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")

View solution in original post

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"
    )

View solution in original post

6 REPLIES 6
AlexisOlson
Super User
Super User

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

Anonymous
Not applicable

I thought formatting the columns as whole numbers get around that but I see what you mean.

Avg_EDI_Grade = IF(Scorecard[Avg_EDI_Points]>3 && IF(Scorecard[Avg_EDI_Points]<=4, "A", IF(Scorecard[Avg_EDI_Points]>2 && IF(Scorecard[Avg_EDI_Points]<=3, "B", IF(Scorecard[Avg_EDI_Points]>1 && IF(Scorecard[Avg_EDI_Points]<=2, "C", IF(Scorecard[Avg_EDI_Points]>0 && IF(Scorecard[Avg_EDI_Points]<=1, "D", IF(Scorecard[Avg_EDI_Points]=0, "F")))))))))

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"
    )

 

Anonymous
Not applicable

Thanks. Thanks worked great. Youre help was much appreciated.

Anonymous
Not applicable

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"
    )

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.