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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
SammyPub
Frequent Visitor

How to get the lowest rank by year for one type

Hi,

 

This is my model

SammyPub_0-1621955983947.png

The Data:

SammyPub_1-1621956114770.png

How can I get the lowest rank by year and type of school?

This is the desired output.

SammyPub_2-1621956210437.png

Thanks

 

 

3 REPLIES 3
Anonymous
Not applicable

Hi @SammyPub,

You can write a formula with 'countrows' and filter based on the current year and type group.

Using the SELECTEDVALUE function in DAX - SQLBI

LRank =
VAR currYear =
    MAX ( Table[Year] )
VAR summary =
    SUMMARIZE (
        ALLSELECTED ( Table ),
        [Year],
        [School],
        "Total", SUM ( Table[value] )
    )
RETURN
    COUNTROWS (
        FILTER (
            summary,
            [Year] = currYear
                && [Total] > SUM ( Table[value] )
        )
    ) + 1

Regards,

Xiaoxin Sheng

Hi Xiaoxin Sheng. Thanks for your help.

 

If it helps. here's the pbix: file 

 

I made a little change since I am looking for the ranking of the grades average and not the sum of the grades.

 

 

LRank = 
VAR currYear =
    MAX ( Results[Year] )
VAR summary =
    SUMMARIZE (
        ALLSELECTED( Results ),
        [Year],
        [IdSchool],
        "Total", AVERAGE ( Results[Grade] )
    )
RETURN
    COUNTROWS (
        FILTER (
            summary,
            [Year] = currYear
                && [Total] > AVERAGE ( Results[Grade] )
        )
    ) 

 

 

I understand the logic, but the results are not what I was expecting:

  • School 1 and School 3 are of the type I, so the best ranking in 2010 was #1 (OK), in 2011 was #1 (OK), but in 2012 was #2 (Not OK, I'm getting #3), and in 2013 was #2 (not #3).
  • For School 2 and School 4 (type 2), the results are ok for all years, except for the year 2013 where it should be #1 instead of #2

I'm looking for the rankings for the best grades by year

SammyPub_0-1622101535301.png

What's wrong?

Thanks

Anonymous
Not applicable

Hi @SammyPub,

I think this should more relate to your visual fields.
My formula is based on school and year but you change them to use school type and it will affect the condition to compare with AVERAGE ( Results[Grade] ) results.

In addition, when you use school type(mapping to multiple schools) as category, power bi will aggregate with these school values. How did you handle this level of aggerate? (Dax expression can't directly calculate with multiple aggregates, you need to add summarize function and iterator functions for different level calculates)

Measure Totals, The Final Word 

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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