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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
aleivar
Frequent Visitor

RANKX in matrix table

Hi All,

I am trying to use single RANKX formula in a matrix table so that the rank is calculated correctly when I drill down.

The image below shows the correct rank for LP

aleivar_0-1680801159476.png

 

But when I drill down, the rank is not calculated correctly. The Rank Total Sales (Brand) shows the correct rank

aleivar_1-1680801249901.png


I tried the following RANK formula but it's not calculating correctly

 

 

 

Rank Total Sales = 
VAR LPGROUPRANK =
RANKX(
    ALL(
        'OCS-daily-2018-2023'[lp_group]
    ),
    [Total Sales],
    ,
    DESC,
    Dense
)
VAR BRANDRANK =
RANKX(
    ALLSELECTED(
        'OCS-daily-2018-2023'[brand]
    ),
    [Total Sales],
    ,
    DESC,
    Dense
)
RETURN
SWITCH(
    TRUE(),
    ISINSCOPE('OCS-daily-2018-2023'[lp_group]
    ),
    LPGROUPRANK,
    ISINSCOPE(
        'OCS-daily-2018-2023'[brand]
    ),
    BRANDRANK
)

 

 


My model looks like this:

aleivar_2-1680801355896.png

 

Any help is greatly appreciated

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @aleivar 

You can try the following measure

Rank Total Sales =
VAR LPGROUPRANK =
    RANKX (
        ALLSELECTED ( 'OCS-daily-2018-2023'[lp_group] ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
VAR BRANDRANK =
    RANKX (
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( 'OCS-daily-2018-2023' ),
                [lp_group] = SELECTEDVALUE ( 'OCS-daily-2018-2023'[lp_group] )
            ),
            [brand]
        ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( ISINSCOPE ( 'OCS-daily-2018-2023'[brand] ), BRANDRANK, LPGROUPRANK )

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
v-xinruzhu-msft
Community Support
Community Support

Hi @aleivar 

You can try the following measure

Rank Total Sales =
VAR LPGROUPRANK =
    RANKX (
        ALLSELECTED ( 'OCS-daily-2018-2023'[lp_group] ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
VAR BRANDRANK =
    RANKX (
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( 'OCS-daily-2018-2023' ),
                [lp_group] = SELECTEDVALUE ( 'OCS-daily-2018-2023'[lp_group] )
            ),
            [brand]
        ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( ISINSCOPE ( 'OCS-daily-2018-2023'[brand] ), BRANDRANK, LPGROUPRANK )

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.