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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
melvin9900
Frequent Visitor

DAX - Calculate rank based on Sales metrics for Sales rep

Hello Community ,

    I am new to PowerBI/Dax world.  We have a report which displays Sales reps performance details. 

It has a dropdown with Sales reps name and once selected it displays the details of corresponding Sales rep.

Something like below, simplified version just to explain.

 

Sales Rep Name : AAAA

Metric         Amt     Rank 

Revenue     1000     Calculate Rank based on Revenue amt (desc) across all reps: Expected value from the table below :  2

Margin       10         Calculate Rank based on Margin amt (desc) across all reps: Expected value from the table below :  3

Debt           2000      Calculate Rank based on Budget amt (ascending) across all reps: Expected value from the table below :  2

 

So we have to calculate the rank of the SaleRep for each Metric across all the reps  based on the Amount.

The table structure is 

 

melvin9900_1-1652296990587.png

 

I am trying to calculate the rank using the DAX formula like Rankx but not getting the value expected. 

Can someone please help me here.

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I created for both calculated column and calculated measure.

 

Slide1.jpg

 

Ranking CC = 
VAR currentmetrics = Data[Metric]
VAR newtable =
    FILTER ( Data, Data[Metric] = currentmetrics )
VAR rankingcurrentmetric =
    RANKX ( newtable, Data[Amount],, DESC )
VAR rankingdebtmetric =
    RANKX ( newtable, Data[Amount],, ASC )
RETURN
    SWITCH (
        TRUE (),
        Data[Metric] IN { "Revenue", "Margin" }, rankingcurrentmetric,
        rankingdebtmetric
    )

 

Amount measure: = 
IF ( ISFILTERED ( Metrics[Metric] ), SUM ( Data[Amount] ) )

 

Ranking measure: = 
VAR currentmetrics =
    MAX ( Metrics[Metric] )
VAR newtable =
    FILTER ( ALL ( Data ), Data[Metric] = currentmetrics )
VAR rankingcurrentmetric =
    RANKX ( newtable, Data[Amount measure:],, DESC )
VAR rankingdebtmetric =
    RANKX ( newtable, Data[Amount measure:],, ASC )
RETURN
    IF (
        ISFILTERED ( Metrics[Metric] ),
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Metrics[Metric] ) IN { "Revenue", "Margin" }, rankingcurrentmetric,
            rankingdebtmetric
        )
    )


Microsoft MVP



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.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I created for both calculated column and calculated measure.

 

Slide1.jpg

 

Ranking CC = 
VAR currentmetrics = Data[Metric]
VAR newtable =
    FILTER ( Data, Data[Metric] = currentmetrics )
VAR rankingcurrentmetric =
    RANKX ( newtable, Data[Amount],, DESC )
VAR rankingdebtmetric =
    RANKX ( newtable, Data[Amount],, ASC )
RETURN
    SWITCH (
        TRUE (),
        Data[Metric] IN { "Revenue", "Margin" }, rankingcurrentmetric,
        rankingdebtmetric
    )

 

Amount measure: = 
IF ( ISFILTERED ( Metrics[Metric] ), SUM ( Data[Amount] ) )

 

Ranking measure: = 
VAR currentmetrics =
    MAX ( Metrics[Metric] )
VAR newtable =
    FILTER ( ALL ( Data ), Data[Metric] = currentmetrics )
VAR rankingcurrentmetric =
    RANKX ( newtable, Data[Amount measure:],, DESC )
VAR rankingdebtmetric =
    RANKX ( newtable, Data[Amount measure:],, ASC )
RETURN
    IF (
        ISFILTERED ( Metrics[Metric] ),
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Metrics[Metric] ) IN { "Revenue", "Margin" }, rankingcurrentmetric,
            rankingdebtmetric
        )
    )


Microsoft MVP



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.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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