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

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.

Reply
KSho
Regular Visitor

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

KSho
Regular Visitor

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

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

 

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

KSho
Regular Visitor

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.