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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Luukvv93
Helper II
Helper II

Need help with ranking measure

Hello community,

 

I have 3 measures from which I only want to show the top 3 values and the bottom 3 values in the same column for the respective measure.

 

S-ratio = MAX(DataUnpivot[Solvabiliteits-ratio])

Debt/EBITDA = MAX(DataUnpivot[Debt/EBITDA-ratio])

DSCR = MAX(DataUnpivot[DSCR column])

tempsnip.png

 

Could you explain me whether to use TOPN or RANKX and if possible send me some code I could realise this.

Your help is much appreciated

 

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @Luukvv93 

To receive below result.

image.png 

 

You can modify below DAX expression. 

 

Rank Top and Bottom Three Sales by Brand =
VAR __grain =
    CALCULATETABLE (
        VALUES ( 'Product'[Brand] ),
        --Rank by Column 
        ALLSELECTED ()
    ) -- replace [Sales] with your Measure
VAR __top =
    RANKX ( __grain, [Sales],, DESC ) <= 3
VAR __bottom =
    RANKX ( __grain, [Sales],, ASC ) <= 3
RETURN
    SWITCH ( TRUE (), __top, [Sales], __bottom, [Sales] )

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn



View solution in original post

3 REPLIES 3
Mariusz
Community Champion
Community Champion

Hi @Luukvv93 

To receive below result.

image.png 

 

You can modify below DAX expression. 

 

Rank Top and Bottom Three Sales by Brand =
VAR __grain =
    CALCULATETABLE (
        VALUES ( 'Product'[Brand] ),
        --Rank by Column 
        ALLSELECTED ()
    ) -- replace [Sales] with your Measure
VAR __top =
    RANKX ( __grain, [Sales],, DESC ) <= 3
VAR __bottom =
    RANKX ( __grain, [Sales],, ASC ) <= 3
RETURN
    SWITCH ( TRUE (), __top, [Sales], __bottom, [Sales] )

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn



Hi @Mariusz 

 

I tried your solution and it seems to work, great.

One question regarding the bottom 3 values:

 

The measure only shows the top 3 ranks (as expected) but only the 2 bottom ranks.

Any clue on how to show the 3 bottom ranks?

 

tempsnip.png

Mariusz
Community Champion
Community Champion

Hi @Luukvv93 

Can you share your DAX Expression?

Thanks
Mariusz

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors