Forum Discussion
More Complexity/Recalculating with RANKX
- Anonymous7 years ago
HI mangoose,
You can try to use below measure formula to get dynamic rank:
Rank District A = IF ( FIRSTNONBLANK ( Store_Data[District], Store_Data[District] ) <> BLANK (), RANKX ( FILTER ( ALLSELECTED ( Store_Data ), Store_Data[District] <> BLANK () ), CALCULATE ( SUM ( Store_Data[Total Volume] ), ALLEXCEPT ( Store_Data, Store_Data[District] ) ),,,DENSE ) ) Rank District B = RANKX ( ALLSELECTED ( Store_Data ), CALCULATE ( SUM ( Store_Data[Total Volume] ), ALLEXCEPT ( Store_Data, Store_Data[District] ) ),,,DENSE )Regards.
Xiaoxin Sheng
Hi mangoose,
Can you please share some sample data to test and coding formula? It is hard to clearly your scenario with any sample data.
BTW, it is hard to achieve dynamic ranking on hierarchy level. In my opinion, maybe you can write multiple calculation formulas for each level, then use if statement to check current level and return correspond calculation result from matched calculation formula.
Regards,
Xiaoxin Sheng
Hi Xiaoxin, happy to provide a demo. Thanks for your reply. I built a .pbix file here: Sample PBIX
Here is as simple as I can explain:
My dataset is as follows:
I created a measure summing up Total Volume, called "TotVol":
TotVol = sum(Store_Data[Total Volume])
Then I made a simple dashboard with both a store and a district leaderboard using rank functions:
As you can see, rankings work when unfiltered for both Store and District - highest volume = #1, second highest #2 etc.
However, when I filter for the "North" region, here is what it looks like:
As you can see, the store ranking is now correct, Store 2591 is now #1 (instead of #5 when unfiltered), but District NB D6 is first on the list, but still displays #5 in both of my rank measures. I want District NB D6 to display "1", and District EA D1 to display "2" etc.
Here are the rank functions (store works well, but neither district rank measures work)
Rank Total Volume Store =
IF (
FIRSTNONBLANK ( Store_Data[Store], Store_Data[Store] ) <> BLANK (),
RANKX (
FILTER ( allselected ( Store_Data ), Store_Data[Store] <> BLANK () ),
CALCULATE ( sum(Store_Data[Total Volume]))
)
)Rank District A =
IF (
FIRSTNONBLANK ( Store_Data[District], Store_Data[District] ) <> BLANK (),
RANKX (
FILTER ( allselected ( Store_Data[District] ), Store_Data[District] <> BLANK () ),
calculate(sum(Store_Data[Total Volume]),allexcept(Store_Data,Store_Data[District]))
)
)Rank District B = rankx(ALLSELECTED(Store_Data[District]),calculate(sum(Store_Data[Total Volume]),allexcept(Store_Data,Store_Data[District])))