Forum Discussion

DMis's avatar
DMis
Regular Visitor
6 years ago

ALLSELECTED and RANKX not working as expected

I have spent last 10 hours or so trying to rank a single field filtered by some other fields and nothing works. It's driving me crazy, when I see a blog entry listing my solution, copy it and it still does not work.

 

Anyhow, I have this model and data:

ModelMarks dataStudent data

 

MarkRank is a calculated column using this formula:

 

MarkRank = RANKX(ALLSELECTED(Marks), Marks[Mark])

 

On the screen below you can see it calculates rank properly over the entire data set.

Initital view

 

However, when I filter by year (or by school or both, it doesn't matter) I get this:

 

Wrong ranking

 

You can see that it does not re-calculate the rank as it should be to rank only displayed values.

 

I tried to change the formula to something like this:

MarkRank = RANKX(ALLSELECTED(Marks[StudentID]), Marks[Mark])
or
MarkRank = RANKX(ALLSELECTED(Marks[Year]), Marks[Mark])
and it would produce only 1 regardless of the field I choose in ALLSELECTED.
 
Ultimately, all I need is to have ranking calculated exclusively over selected values using filters from any table, Marks or Students.
 
Download  link for PBI project: https://file.io/BkfZ8UmI

8 Replies