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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
akhilduvvuru
Helper IV
Helper IV

Don't change the previous rank based on selection

Hi, I have 20 students and marks related data by semester where I want to show a table in Power BI with these fields Student Name, Current Semester Rank, Previous Semester Rank, Current Semester Marks, Previous Semester Marks. 

I should also need a Top N slicer in the dashboard where we should be able to filter the Top students by Current Semester Rank.


I have created 2 rank measures based on Current Semester Marks and Previous Semester Marks as following.

 

Current Semester Rank = RANKX(ALLSELECTED(STUDENTSTABLE[Student Name]), SUM(STUDENTTABLE[Current Semester Marks]),, DESC, Dense)
Previous Semester Rank = RANKX(ALLSELECTED(STUDENTSTABLE[Student Name]), SUM(STUDENTTABLE[Previous Semester Marks]),, DESC, Dense)

 

Using the above Rank mesures, I'm getting the right result when I show the data for all the students.

Student NameCurrent Semester RankPrev Semester RankPrev Semester MarksCurrent Semester Marks
Alex14924954
Bobby27889930
Jacob31956910
Michael43927900
Andrew516833890
Mathew617828850
Austin712853840
David810873835
Chris913851832
Nick105922827
Nathan116890824
Anthony1220808820
Victoria1315841818
Brittany1418824815
Jasmine159881812
Emilu1614843810
Jessica178886809
Emma1811872808
Rachel192952805
Magen2019810804

 

However the issue is with Top N slicer. When I apply the Top N slicer to show only Top 5, Andrew's Prev Semester Rank was 16 (changed to 5) also Bobby's Prev Semester Rank was 5 (changed to 2).

Student NameCurrent Semester RankPrev Semester RankPrev Semester MarksCurrent Semester Marks
Alex14924954
Bobby22889930
Jacob31956910
Michael43927900
Andrew55833890

 

Same with Top 10 as well, Bobby was at 7 (changed to 2), Andrew was at 16 (changed to 5), Mathew was at 17 (changed to 9) etc.,

Student NameCurrent Semester RankPrev Semester RankPrev Semester MarksCurrent Semester Marks
Alex14924954
Bobby22889930
Jacob31956910
Michael43927900
Andrew55833890
Mathew69828850
Austin78853840
David810873835
Chris97851832
Nick105922827

 

One observation is - It islimiting the Prev Semester Ranks within the Top N slicer value.

 

I don't want the Prev Semester Rank to change. Not sure how to handle this. Can someone please help with this?

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @akhilduvvuru ,

I think that's the problem, because your Current Semester Marks and Previous Semester Marks are both measures, so when you use slicer for filtering, not only are the 2 Rank measures affected by slicer, but so are both measures will also be affected by slicer. 
When you slicer filter the Top5, your two Marks measures, because they are also affected by the slicer, cause them to return only the values corresponding to the 5 students, so the subsequent Rank will only sort on those 5 values instead of on all values.
Please change your DAXs into these and it should be OK:

Current Semester Rank = RANKX(ALL(STUDENTSTABLE), 'STUDENTSTABLE'[Current Semester Marks], , DESC, Dense)
Previous Semester Rank = RANKX(ALL(STUDENTSTABLE), 'STUDENTSTABLE'[Previous Semester Marks], , DESC, Dense)


Output:

vjunyantmsft_0-1728883477476.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

11 REPLIES 11
Anonymous
Not applicable

Hi @akhilduvvuru ,

Try to change the measure into these:

Current Semester Rank = 
RANKX(ALL(STUDENTSTABLE), 'STUDENTSTABLE'[Current Semester Marks], MAX('STUDENTSTABLE'[Current Semester Marks]), DESC, Dense)
Previous Semester Rank = 
RANKX(ALL(STUDENTSTABLE), 'STUDENTSTABLE'[Prev Semester Marks], MAX('STUDENTSTABLE'[Prev Semester Marks]), DESC, Dense)

And the final output is as below:

vjunyantmsft_0-1728542381406.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous Thanks for the response.

"Current Semester Marks" and "Prev Semester Marks" which I mentioned are measures which I created using a field called Marks. Hence, can't directly use them as you mentioned in your response.

for example: 

Current Semester Marks = CALCULATE(SUM(STUDENTSTABLE[Marks]), STUDENTSTABLE[Grade] = "Two", STUDENTSTABLE[Status] = "Active", STUDENTSTABLE[QuarterFlag} = "Current Quarter")
Previous Semester Marks = CALCULATE(SUM(STUDENTSTABLE[Marks]), STUDENTSTABLE[Grade] = "Two", STUDENTSTABLE[Status] = "Active", STUDENTSTABLE[QuarterFlag} = "Previous Quarter")

 

Anonymous
Not applicable

Hi @akhilduvvuru ,

I think that's the problem, because your Current Semester Marks and Previous Semester Marks are both measures, so when you use slicer for filtering, not only are the 2 Rank measures affected by slicer, but so are both measures will also be affected by slicer. 
When you slicer filter the Top5, your two Marks measures, because they are also affected by the slicer, cause them to return only the values corresponding to the 5 students, so the subsequent Rank will only sort on those 5 values instead of on all values.
Please change your DAXs into these and it should be OK:

Current Semester Rank = RANKX(ALL(STUDENTSTABLE), 'STUDENTSTABLE'[Current Semester Marks], , DESC, Dense)
Previous Semester Rank = RANKX(ALL(STUDENTSTABLE), 'STUDENTSTABLE'[Previous Semester Marks], , DESC, Dense)


Output:

vjunyantmsft_0-1728883477476.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Kedar_Pande
Super User
Super User

@akhilduvvuru  

You can adjust your DAX measures by using ALL to ignore the slicer filter context for "Previous Semester Rank."

Current Semester Rank (No change needed here):

Current Semester Rank = 
RANKX(ALLSELECTED(STUDENTSTABLE[Student Name]), SUM(STUDENTTABLE[Current Semester Marks]),, DESC, DENSE)

 

Previous Semester Rank (Modified to ignore Top N filter):

Previous Semester Rank = 
RANKX(
ALL(STUDENTSTABLE[Student Name]),
SUM(STUDENTTABLE[Previous Semester Marks]),
, DESC, DENSE
)

If this helped, a Kudos 👍 or Solution mark would be great!
Cheers,
Kedar Pande
www.linkedin.com/in/kedar-pande

@Kedar_Pande - Thanks for the quick response. I tried that already but the same rank is repeating for few students even the marks are different between them.

Can you share the file please.

Upload in drive and share the link here

rajendraongole1
Super User
Super User

Hi @akhilduvvuru - Instead of using a measure for the "Previous Semester Rank," you can create a calculated column for the rank based on all students, which will not be affected by the Top N filter.

 

Previous Semester Rank (Static) =
RANKX(
ALL(STUDENTTABLE[Student Name]),
CALCULATE(SUM(STUDENTTABLE[Previous Semester Marks])),
,
DESC,
DENSE
)

 

You can still use the measure for the "Current Semester Rank" since this should dynamically change based on the Top N slicer

 

Current Semester Rank =
RANKX(
ALLSELECTED(STUDENTTABLE[Student Name]),
SUM(STUDENTTABLE[Current Semester Marks]),
,
DESC,
DENSE
)

 

Add a slicer for the Top N students, but now the "Previous Semester Rank" will remain consistent even when filtering the top students based on "Current Semester Rank."

add the visual and check the visual by adding the fields 

rajendraongole1_0-1728452058922.png

 

Hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





@rajendraongole1 - Thanks for your quick response. While creating the Prev Semester Rank column, I'm getting a circular dependency error with one other calculated column which I had created in the same table for some other usecase.

akhilduvvuru
Helper IV
Helper IV

OktayPamuk80
Responsive Resident
Responsive Resident

Hi,

If the data should not be dynamic relating to ranking, the solution would be having ranking pre calculated in power query e.g using index and custom columns. Issue is as you stated, that the calculated values change, because calculation instantly takes place based on the selection, which you want to avoid.

 

Does this help you?

Regards,
Oktay

 

Did I answer your question? Then please mark my post as the solution.

If I helped you, click on the Thumbs Up to give Kudos.

Hey @OktayPamuk80 - Thanks for your response.

 

I cannot do it in the Power Query. My doubt is even though the semester marks are not changing, why is my rank changing?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors