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! Learn more

Reply
Anonymous
Not applicable

dynamic rank with hierarchy in matrix

Hi, I want to create a rank measure with dynamic and should consider the slicer, but I have no idea how to solve it, here is my data and expected result, hope to get some ideas to solve it.

data:

null_0-1673535131211.png

I dragged the category and sub category in rows, and "value" to values, 

expected result with rank of total in matrix, the blue background is total row in matrix, the rank should be order by descending

null_1-1673535212002.png

 

 

 

1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

HI @Anonymous 

 

Please try the following:

 

data

Mikelytics_1-1673537095329.png

 

Measure:

 

RANK | 2 dim rank = 

    IF(
        ISINSCOPE(SampleDynamicRank[sub_category]),

        RANKX(
            ALLEXCEPT(SampleDynamicRank,SampleDynamicRank[Category])
            ,CALCULATE(SUM(SampleDynamicRank[value]))
        )
        ,
        RANKX(
            ALL(SampleDynamicRank[category])
            ,CALCULATE(SUM(SampleDynamicRank[value]))
        )
    )

 

@Anonymous I updated the formula by replacing HASONEVALUE with ISINSCOPE. THe version before had a bug when there was only one sub category under a category. Using ISINSCOPE it works fine

 

Result

Mikelytics_0-1673538142486.png

 

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

1 REPLY 1
Mikelytics
Resident Rockstar
Resident Rockstar

HI @Anonymous 

 

Please try the following:

 

data

Mikelytics_1-1673537095329.png

 

Measure:

 

RANK | 2 dim rank = 

    IF(
        ISINSCOPE(SampleDynamicRank[sub_category]),

        RANKX(
            ALLEXCEPT(SampleDynamicRank,SampleDynamicRank[Category])
            ,CALCULATE(SUM(SampleDynamicRank[value]))
        )
        ,
        RANKX(
            ALL(SampleDynamicRank[category])
            ,CALCULATE(SUM(SampleDynamicRank[value]))
        )
    )

 

@Anonymous I updated the formula by replacing HASONEVALUE with ISINSCOPE. THe version before had a bug when there was only one sub category under a category. Using ISINSCOPE it works fine

 

Result

Mikelytics_0-1673538142486.png

 

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.