cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## How to get the lowest rank by year for one type

Hi,

This is my model

The Data:

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

This is the desired output.

Thanks

3 REPLIES 3
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Frequent Visitor

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],
)
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

What's wrong?

Thanks

Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors