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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Top and Bottom 5 with RANKX based on other measures

Hi all, 

I need to calculate a top and bottom 5 employees based on the result of two measures. 

I tried to use RANKX but the problem is that I need to take into account two measures. Like a double ranking...

 

Below 3 examples:

'Collis checked' and 'Total Over Picking' are measures

1) JulieB__1-1651665476626.png
 
2) JulieB__0-1651664668243.jpeg
 
3) JulieB__2-1651665528617.png
1)
Show the BOTTOM 5 'GOLD numbers bereider' with the most 'total over picking'.
(!) Take into consideration who has the most 'collis checked'.
(!) Total over picking can be BLANK or contain a number
In the example left this is the desired result:
1. 294
2. 311
3. 450
4. 844
5. blank
 
 
 
2)
Show the TOP 5 'GOLD numbers bereider' with the less 'total over picking'.
(!) Take into consideration who has the most 'collis checked'.
(!) Total over picking can be BLANK or contain a number
In the example left this is the desired result:
1. 065
2. 431
3. 942
4. 248
5. 816
 
 

3)

Show the TOP 5 'GOLD numbers bereider' with the less 'total over picking'.

(!) Take into consideration who has the most 'collis checked'.
(!) Total over picking can be BLANK or contain a number
In the example left this is the desired result:
1. 696
2. 487
3. 140
4. 051
5. 722
 
 

 

I created a test powerbi file with sample data. You can download the test file via this link in WeTransfer: https://we.tl/t-tr6d0dzIQH

 

Hope someone can help out. I already broke my head hours on this one... 😞

 

1 ACCEPTED SOLUTION

Hi, @Anonymous 

For your last requirement, please try formula as below:

 

Ranking = 
RANKX (
    ALLSELECTED( Data[CODPRE] ),
    RANKX ( ALLSELECTED( Data[CODPRE] ), [Total Over picking],,DESC )
        + DIVIDE (
            RANKX ( ALLSELECTED( Data[CODPRE] ), [Collis checked],,DESC ),
            COUNTROWS ( ALLSELECTED( Data[CODPRE] ) ) + 1
        )
        ,,
    ASC,
    DENSE
)
Ranking(<5) = 
IF([Ranking]<=5,[Ranking],BLANK())

 

15.png

Please check my sample file for more details.

Best Regards,
Community Support Team _ Eason

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , File seem to have some different data. you need try like

 

top and bottom 5 = CALCULATE([Total Over picking],TOPN(5,ALLSELECTED(Data[CODPRE]),[Total Over picking],DESC),VALUES(Data[CODPRE]))+ CALCULATE([Total Over picking],TOPN(5,ALLSELECTED(Data[CODPRE]),[Total Over picking],ASC),VALUES(Data[CODPRE]))
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

hi @amitchandak , your proposed solution is not exactly what I try to obtain

 

JulieB__1-1651763764202.png

 


 

Your 'top and bottom 5' returns the value of the 'total over picking'. I would like it to return a ranking (number 1 to 5).

 

Also if the top 5 of the 'total over picking' contains several times the same value then it should look at the 'collis checked' measure to rank those values. 

 

In the left example:

top 5 result would be 

collis checkedtotal over pickingtop 5 (ranking)
108102
166101
553
3045
33744

 

 

 

You know how I can do this? 🙂

Thanks!

Hi, @Anonymous 

For your last requirement, please try formula as below:

 

Ranking = 
RANKX (
    ALLSELECTED( Data[CODPRE] ),
    RANKX ( ALLSELECTED( Data[CODPRE] ), [Total Over picking],,DESC )
        + DIVIDE (
            RANKX ( ALLSELECTED( Data[CODPRE] ), [Collis checked],,DESC ),
            COUNTROWS ( ALLSELECTED( Data[CODPRE] ) ) + 1
        )
        ,,
    ASC,
    DENSE
)
Ranking(<5) = 
IF([Ranking]<=5,[Ranking],BLANK())

 

15.png

Please check my sample file for more details.

Best Regards,
Community Support Team _ Eason

Anonymous
Not applicable

Thank you @v-easonf-msft! That measure is exactly what I needed!
Would never have been able to figure that out all by myself 😳

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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