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
ranjitsingh
Advocate I
Advocate I

DAX Challenge

Hi All,

 

I have the following sales table where I need to find annual ranking of salesperson but there is a small complexity....

 

The ranking depends not only on number of annual car sales by the sales person but also takes into account how long the employee has been with the company. Shorter employment period is ranked higher. E.g. Sale of 70 cars for sonita will be ranked higher than sale of 70 cars by ravita as sonita has been with the company since only 2019, and still sold the same # of cars as ravita who has much greater experience..

 

Not sure how to write this in DAX to get a ranking system...?? 

 

EMPLOYEE_IDFIRST_NAMEAnnual Car SalesDate of JoiningAnnual Ranking
100vinita1101-Jan-05 
110sonita7012-Jun-19 
120ravita7019-Apr-04 
130sarita501-Mar-08 
140minita9512-Feb-20 
150binita302-Oct-14 
160lonita4516-Sep-11 
170robita6511-Oct-09 
180papita274-May-18 
190tomita2023-Dec-20 

 

1 ACCEPTED SOLUTION

@ranjitsingh , I chanced on this video and improved the measure; you might want to refer to it as well,

 

Annual Ranking =
VAR __delta = MAX ( Sales[Date of Joining] )
RETURN
    RANKX (
        ALLSELECTED ( Sales[EMPLOYEE_ID] ),
        CALCULATE (
            SUM ( Sales[Annual Car Sales] ) * __delta + SUM ( Sales[Date of Joining] ),
            ALLEXCEPT ( Sales, Sales[EMPLOYEE_ID] )
        )
    )

 

Screenshot 2021-03-23 114228.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

6 REPLIES 6
CNENFRNL
Community Champion
Community Champion

@ranjitsingh , you might want to try

 

 

Annual Ranking = 
RANKX (
    ALLSELECTED ( Sales[EMPLOYEE_ID] ),
    CALCULATE (
        SUM ( Sales[Annual Car Sales] ) + SUM ( Sales[Date of Joining] ) / 10000, 
        ALLEXCEPT(Sales, Sales[EMPLOYEE_ID] )
    )
)

 

 

Screenshot 2021-03-23 042836.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL  I dont have my workstation currently, but will try this in office tomorrow and let you know if this works. Thanks so much for your help!

@ranjitsingh , I chanced on this video and improved the measure; you might want to refer to it as well,

 

Annual Ranking =
VAR __delta = MAX ( Sales[Date of Joining] )
RETURN
    RANKX (
        ALLSELECTED ( Sales[EMPLOYEE_ID] ),
        CALCULATE (
            SUM ( Sales[Annual Car Sales] ) * __delta + SUM ( Sales[Date of Joining] ),
            ALLEXCEPT ( Sales, Sales[EMPLOYEE_ID] )
        )
    )

 

Screenshot 2021-03-23 114228.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thanks!

AlexisOlson
Super User
Super User

When ranking, is the employment period only used for tie-breaking?

yes indeed only for tie breaking..sorry should have been more clear ...

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