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
AyeshaA10
Frequent Visitor

Bottom N based on Condition

Hi!

 

I am very new to Power BI and this is my first post here on the Power BI forums. I have previously found quite a few gems on here that I applied to my work. I am hoping I might get an answer to my problem below:

 

I am working with a student academic performance dataset. I am required to create a list of top 10 best performing students as well as a list of 10 at-risk (worst performing) students. This is easily done using Filters. Where I am facing an issue is I need to add a condition to the list of 10 at-risk students. If the total mark is below 50, then I show them on the list, otherwise I leave the list empty. My pseudocode is something like this,

If 'GradingData'[Total] < 50, then show in table else leave table empty.

How can I go about achieving this? Thank you in advance!

3 ACCEPTED SOLUTIONS
archuleta28
Resolver I
Resolver I

Hi @AyeshaA10 ,

 

You can use filters in your case to showcase your results:

 

Capture.JPG

 

Hope this helps, please let me know if this doesnot work out.

View solution in original post

johnt75
Super User
Super User

Create a measure like

Is At Risk =
VAR CurrentStudent =
    SELECTEDVALUE ( 'Grading Data'[Student ID] )
VAR AtRiskStudents =
    TOPN ( 10, ALL ( 'Grading Data' ), 'Grading Data'[Total], ASC )
VAR VisibleAtRiskStudents =
    SELECTCOLUMNS (
        FILTER ( AtRiskStudents, 'Grading Data'[Total] < 50 ),
        'Grading Data'[Student ID]
    )
VAR Result =
    IF ( CurrentStudent IN VisibleAtRiskStudents, 1 )
RETURN
    Result

and add this as a visual level filter to only show when the value is 1

View solution in original post

Thank you very much for your help! I've saved this DAX measure. I think this is going to come in handy later.

View solution in original post

5 REPLIES 5
johnt75
Super User
Super User

Create a measure like

Is At Risk =
VAR CurrentStudent =
    SELECTEDVALUE ( 'Grading Data'[Student ID] )
VAR AtRiskStudents =
    TOPN ( 10, ALL ( 'Grading Data' ), 'Grading Data'[Total], ASC )
VAR VisibleAtRiskStudents =
    SELECTCOLUMNS (
        FILTER ( AtRiskStudents, 'Grading Data'[Total] < 50 ),
        'Grading Data'[Student ID]
    )
VAR Result =
    IF ( CurrentStudent IN VisibleAtRiskStudents, 1 )
RETURN
    Result

and add this as a visual level filter to only show when the value is 1

Thank you very much for your help! I've saved this DAX measure. I think this is going to come in handy later.

archuleta28
Resolver I
Resolver I

Hi @AyeshaA10 ,

 

You can use filters in your case to showcase your results:

 

Capture.JPG

 

Hope this helps, please let me know if this doesnot work out.

Thank you so much for your help. This worked great! 

Glad to help! 🙂

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.