Forum Discussion
Rankx Not working as expected when data is filtered using slicers and filter pane
- Anonymous1 year ago
Hi Vivek26
Please check this measure. Although it is not concise enough, it seems to meet your requirements.
rank = var currentDistrict = SELECTEDVALUE(Store[District]) var sumTable = SUMMARIZE(ALLSELECTED(Store),Store[Region],Store[District],"Total_Amount",[Total Sales]) var rankTable = ADDCOLUMNS(sumTable,"Rank_Value",RANK(DENSE,sumTable,ORDERBY([Total_Amount],DESC))) return MAXX(FILTER(rankTable,[District] = currentDistrict),[Rank_Value])I struggled a lot but haven't figured out a method with RANKX yet. Hope this would be helpful.
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!
9 Replies
- Greg_Deckler
Community Champion
Vivek26 What do you mean by "DAX breaks"? You get an error, you get incorrect results, ... ? You might try RANK instead of RANKX
- Vivek26
Advocate I
Hi Greg , Thanks for replying.
The dax doesn't break but the ranking order gets messed up
For example post filtering , Kanpur may get the 3rd Rank while it should be 2nd
District|Total Sales|RankBasedonSalesDelhi|10000|1Kanpur|9000|3Nagpur|8000|2 - powerbiexpert22
Impactful Individual
Hi Vivek26,
please see below pbix for your reference , the rankx function is showing correct results
you will have to create measure first for sales amount and then use it inside rank function ( do not use sum(col) directly in your rank measure
https://drive.google.com/file/d/1TmjidSpb2KktCGYUkfRDQlnc_nAWsL3L/view?usp=drive_link
- Vivek26
Advocate I
powerbiexpert22 . Thanks for replying.
I used your pbix but instead of having 3 different slicers . I used a single one and I started getting the same issue.
My Apoligies I should have clarified my usage of slicer
- powerbiexpert22
Impactful Individual
Hi Vivek26 ,
try to use below
rank =RANKX(ALLSELECTED(store[region],store[district],store[storeid]),[Total Sales],,DESC,Dense)
- Vivek26
Advocate I
If you filter a specific store in a district, we will again start getting rank 1 for everything . That is my main point of concern.
In a district we want to exclude certain stores .
- AnonymousNot applicable
Hi Vivek26
Please check this measure. Although it is not concise enough, it seems to meet your requirements.
rank = var currentDistrict = SELECTEDVALUE(Store[District]) var sumTable = SUMMARIZE(ALLSELECTED(Store),Store[Region],Store[District],"Total_Amount",[Total Sales]) var rankTable = ADDCOLUMNS(sumTable,"Rank_Value",RANK(DENSE,sumTable,ORDERBY([Total_Amount],DESC))) return MAXX(FILTER(rankTable,[District] = currentDistrict),[Rank_Value])I struggled a lot but haven't figured out a method with RANKX yet. Hope this would be helpful.
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos! - powerbiexpert22
Impactful Individual
Hi Vivek26 ,
can you let me know in which scenario in my pbix file is giving all ones?
- Vivek26
Advocate I
Anonymous . Thanks a lot for the reply. The solution worked.
Please do let me know if you are able to solve it with Rankx as well.
I also Invested a lot of time with Rankx but I was not able to find a good solution.