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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
spartanboy
Helper II
Helper II

Dynamic Rankx Measure

Hello Experts!

In the below pbi snippet, please help in creating a dynamic ranking, expectation here is the rank for each months should change with drill up or drill down.

The ranking is supposed to be per SKU_ID & COST_TYPE, ranked by suppliers. At the end, the matrix should answer how the Suppliers are ranking against other suppliers for a given SKU_ID/COST_TYPE/TIME_FRAME

 

Access linke: https://www.dropbox.com/s/8q0d95e5edp5wze/Sample_PBI.pbix?dl=0

 

spartanboy_0-1657818470995.png

 

 

Thanks,

 

 

@amitchandak 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below measure and the attached pbix file.

 

Ranking measure: =
SWITCH (
    TRUE (),
    ISINSCOPE ( Sample_Data[MFG_ID] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    ALL ( Sample_Data ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        ),
    ISINSCOPE ( Sample_Data[REGION] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    SUMMARIZE (
                        ALL ( Sample_Data ),
                        Sample_Data[SKU_ID],
                        Sample_Data[COST_GROUP],
                        Sample_Data[COST_TYPE],
                        Sample_Data[REGION],
                        Sample_Data[TIME_FRAME]
                    ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        ),
    ISINSCOPE ( Sample_Data[COST_TYPE] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    SUMMARIZE (
                        ALL ( Sample_Data ),
                        Sample_Data[SKU_ID],
                        Sample_Data[COST_GROUP],
                        Sample_Data[COST_TYPE],
                        Sample_Data[TIME_FRAME]
                    ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        ),
    ISINSCOPE ( Sample_Data[COST_GROUP] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    SUMMARIZE (
                        ALL ( Sample_Data ),
                        Sample_Data[SKU_ID],
                        Sample_Data[COST_GROUP],
                        Sample_Data[TIME_FRAME]
                    ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        ),
    ISINSCOPE ( Sample_Data[SKU_ID] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    SUMMARIZE ( ALL ( Sample_Data ), Sample_Data[SKU_ID], Sample_Data[TIME_FRAME] ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

Hi,

Thank you for your message.

Please check the attached file, if I correctly created a different table for a Region table.

Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi,

Please check the below measure and the attached pbix file.

 

Ranking measure: =
SWITCH (
    TRUE (),
    ISINSCOPE ( Sample_Data[MFG_ID] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    ALL ( Sample_Data ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        ),
    ISINSCOPE ( Sample_Data[REGION] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    SUMMARIZE (
                        ALL ( Sample_Data ),
                        Sample_Data[SKU_ID],
                        Sample_Data[COST_GROUP],
                        Sample_Data[COST_TYPE],
                        Sample_Data[REGION],
                        Sample_Data[TIME_FRAME]
                    ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        ),
    ISINSCOPE ( Sample_Data[COST_TYPE] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    SUMMARIZE (
                        ALL ( Sample_Data ),
                        Sample_Data[SKU_ID],
                        Sample_Data[COST_GROUP],
                        Sample_Data[COST_TYPE],
                        Sample_Data[TIME_FRAME]
                    ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        ),
    ISINSCOPE ( Sample_Data[COST_GROUP] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    SUMMARIZE (
                        ALL ( Sample_Data ),
                        Sample_Data[SKU_ID],
                        Sample_Data[COST_GROUP],
                        Sample_Data[TIME_FRAME]
                    ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        ),
    ISINSCOPE ( Sample_Data[SKU_ID] ),
        IF (
            [Calculate_WT_AVG_COST] <> BLANK (),
            RANKX (
                FILTER (
                    SUMMARIZE ( ALL ( Sample_Data ), Sample_Data[SKU_ID], Sample_Data[TIME_FRAME] ),
                    [Calculate_WT_AVG_COST] <> BLANK ()
                        && Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
                ),
                [Calculate_WT_AVG_COST],
                ,
                DESC
            )
        )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

@Jihwan_Kim : It all works, greatly appreciated! One last: What-if the "REGION" is coming from another table? on just changing all the ranking are displayed as 1. Please help..

Hi,

Thank you for your message.

Please check the attached file, if I correctly created a different table for a Region table.

Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thanks for providing the solution. One final request - How can i NOT rank a supplier (eg: Supplier 1).

 

Attached file.

https://www.dropbox.com/s/8q0d95e5edp5wze/Sample_PBI.pbix?dl=0

Hi,

I am not sure if I understood correctly, but when I saw the file in the link, I think ranking except supplier3 was tried.

I tried to create a measure like below, and please check the attached file if it suits the requirement.

 

Ranking except Supplier_3: =
VAR _newtable =
    FILTER (
        SUMMARIZE (
            ALL ( Sample_Data ),
            Sample_Data[PRODUCT_GROUP],
            Sample_Data[SKU_ID],
            Sample_Data[COST_GROUP],
            Sample_Data[COST_TYPE],
            Sample_Data[MFG_ID],
            Sample_Data[TIME_FRAME]
        ),
        Sample_Data[TIME_FRAME] = MAX ( Sample_Data[TIME_FRAME] )
            && Sample_Data[COST_TYPE] = MAX ( Sample_Data[COST_TYPE] )
            && Sample_Data[COST_GROUP] = MAX ( Sample_Data[COST_GROUP] )
            && Sample_Data[SKU_ID] = MAX ( Sample_Data[SKU_ID] )
            && Sample_Data[PRODUCT_GROUP] = MAX ( Sample_Data[PRODUCT_GROUP] )
            && Sample_Data[MFG_ID] <> "SUPPLIER_3"
    )
RETURN
    IF (
        SELECTEDVALUE ( Sample_Data[MFG_ID] ) <> "SUPPLIER_3",
        RANKX ( _newtable, [Calculate_WT_AVG_COST],, ASC )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.