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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
        )
    )

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

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
        )
    )

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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