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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
AnniekH96
Frequent Visitor

Ranking among three groups > return name of top 2

Hi everyone, 

 

I got a large dataset(2M> rows) with 5 columns:

  • Institution
  • Year
  • Region
  • Course
  • Number of students

I want to rank the within each year, region and course the number of students. For example the first 4 rows have the same year, region and course so they get ranked together. 

 

Secondly, I want a column(or measure) that returns the institution of the highest two ranking institution, all others get the label "Others."

 

I can't seem to find a rankx that allows the multiple groups. I would really appreciate some help!!

 

InstitutionYearRegionCourseNumber op studentsRankingGrouping
30RR2019Frieslandtotaal;008;bbl;415230RR
30RM2019Frieslandtotaal;008;bbl;4123Others
25PJ2019Frieslandtotaal;008;bbl;447125PJ
08PG2019Frieslandtotaal;008;bbl;434Others
25PJ2019Frieslandtotaal;057;bbl;416125PJ
08PG2018Frieslandtotaal;008;bbl;438108PG
25PJ2018Frieslandtotaal;008;bbl;434225PJ
30RM2018Frieslandtotaal;008;bbl;4303Others
AATR2018Frieslandtotaal;008;bbl;4124Others
30RM2019Midden-Utrechttotaal;057;bbl;412130RM
30RR2019Midden-Utrechttotaal;008;bbl;417230RR
30RM2019Midden-Utrechttotaal;008;bbl;439130RM
25PJ2019Midden-Utrechttotaal;008;bbl;425Others
08PG2019Midden-Utrechttotaal;008;bbl;434Others 
AATR2019Midden-Utrechttotaal;008;bbl;4153Others
30RM2018Midden-Utrechttotaal;057;bbl;444130RM
30RR2018Midden-Utrechttotaal;057;bbl;47230RR
30RR2018Midden-Utrechttotaal;008;bbl;425230RR
25LG2018Midden-Utrechttotaal;008;bbl;438125LG
1 REPLY 1
amitchandak
Super User
Super User

@AnniekH96 , If [Number op students] is a column and you need column rank .

 

If nedd measure rank. Make sure [Number op students] is measure or create a measure and use that in rank = sum(Table[Number op students])

 

Rankx(filter(Table, [year] =earlier([year]) && [region] =earlier([region]) && [course] =earlier([course]) ),[Number op students])

Rankx(filter(allselected(Table[Year], Table[region], Table[course]), Table[, [year] =earlier([year]) && [region] =earlier([region]) && [course] =earlier([course]) ),[Number op students])

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.