Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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 

 

  • CNENFRNL's avatar
    CNENFRNL
    5 years ago

    Anonymous , 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] )
            )
        )

     

6 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

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

  • CNENFRNL's avatar
    CNENFRNL
    Community Champion

    Anonymous , 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] )
        )
    )

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      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!

      • CNENFRNL's avatar
        CNENFRNL
        Community Champion

        Anonymous , 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] )
                )
            )