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
Anonymous
Not applicable

Dynamic RANKX function

Hi,

I have a requirement where I have employees and their marks by class and year as mentioned below. In the below example, Class and Year are two slicers. Based on this slicers selection I have to rank the employees based on their marks.

Actual Data:

EmployeeNameTotal MarksYearClass
Abhishek7920195
Anand2320195
Peter9020195
Bliss3420195
Mike5820186
Sofia9720186
Paul4720186
Chris6520186
Raman4520175
Raju2320175
Mohan9620164
Vinod2920164
Chaitanya5620164
Karthik2920164

 

For example 1: If I select 2019 as Year and 5 as Class, then my expected output should be

EmployeeNameTotal MarksRank
Abhishek792
Anand234
Peter901
Bliss343

For example 2: If I select 2016 as Year and 4 as Class, then my expected output should be

EmployeeNameTotal MarksRank
Mohan961
Vinod293
Chaitanya562
Karthik293

Can someone help me with how to get this in Power BI using DAX to work dynamically on Slicer selection?

 

Thanks in advance!

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

You can use following measure

 

Measure =
RANKX (
    ALLSELECTED ( Table1[EmployeeName] ),
    CALCULATE ( SUM ( Table1[Total Marks] ) ),
    ,
    DESC,
    DENSE
)

Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

You can use following measure

 

Measure =
RANKX (
    ALLSELECTED ( Table1[EmployeeName] ),
    CALCULATE ( SUM ( Table1[Total Marks] ) ),
    ,
    DESC,
    DENSE
)

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

@Zubair_Muhammad  - Thanks for your help. This works!

Anonymous
Not applicable

Hi @Zubair_Muhammad 

I have another requirement along with the above requirement. 

 

The requirement is I already have Rank based on Total Marks. Now, I want the Row Number also to be displayed in the report. The key thing is it should be dynamic based on the year selection in the slicer. 

For Example: If I select 2018 a year, then the Rank and Row Number should start from 1 based on the Total Marks. The Rank column is working as per the requirement. Now I need the Row Number.

EmployeeNameYearTotal MarksRankRow Number
Sofia20199711
Mohan20199622
Peter20199033
Abhishek20199034
Chris20189035
Mike20185846
Chaitanya20185847
Paul20184758
Raman20174569
Bliss201734710
Vinod201734711
Karthik201729812
Anand201623913
Raju201623914

 

Can you please help me with the same?

 

Thanks in advance

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.

Top Solution Authors