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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
mangoose
Frequent Visitor

More Complexity/Recalculating with RANKX

I have read all over, and havent found something useful.

 

I have a dataset with 5 levels of hierarchy, and I am trying to create a leaderboard dashboard at different levels using the same slicer: when slicing for region, i need it to rank all levels of the hierarchy, not just the lowest level (store).

 

When trying to rank the "district" level (1 up from store), Im able to get a rank which works when unfiltered, and i end up with 1,2,3,4,5,...etc.

but when filtered, it doesnt rerank, and instead cuts out the filtered rows so I end up with 4,8,15,...etc.

 

Is there a way to filter and recalculate rank?

 

Here is the measure I created:

Rank5 = 
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])),,,SKIP
    )
)

 

thanks! 

1 ACCEPTED SOLUTION

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
)

10.PNG

 

Regards.
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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:
Dataset.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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:

Dashboard Unfiltered.PNG

 

 

 

 

 

 

 

 

 

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:Dashboard Filtered.PNG

 

 

 

 

 

 

 

 

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])))

 

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
)

10.PNG

 

Regards.
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors