cancel
Showing results for
Did you mean:
Helper I

Challenge ?

Hi All,

I have the following sales table where I need to find annual ranking of salesperson.

There is a small complication....

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_ID FIRST_NAME Annual Car Sales Date of Joining Annual Ranking 100 vinita 110 1-Jan-05 110 sonita 70 12-Jun-19 120 ravita 70 19-Apr-04 130 sarita 50 1-Mar-08 140 minita 95 12-Feb-20 150 binita 30 2-Oct-14 160 lonita 45 16-Sep-11 170 robita 65 11-Oct-09 180 papita 27 4-May-18 190 tomita 20 23-Dec-20

Solution Sage
``````DEFINE
MEASURE 'Ranking Exercise'[Total Sales] =
SUM( 'Ranking Exercise'[Annual Car Sales] )

MEASURE 'Ranking Exercise'[Tenure Days] =
// You need to create a column 'Ranking Exercise'[Days With Company]
// that will equal Today() - RankingExercise[Date of Joining].
// or you can replace the SUM below with:
//    SUMX(
//        'Ranking Exercise',
//        TODAY() - 'Ranking Exercise'[Date of Joining]
//    )
SUM( 'Ranking Exercise'[Days With Company] )

MEASURE 'Ranking Exercise'[Employee Rank] =
IF( ISINSCOPE( 'Ranking Exercise'[FIRST_NAME] ),
var vEmps =
ALLSELECTED(
'Ranking Exercise'[FIRST_NAME]
)
var vEmpsWithRanks =
vEmps,
"@EmpRank",
CALCULATE(
RANKX(
vEmps,
[Total Sales],,
DESC
)
)
)
var vCurrentEmp = SELECTEDVALUE( 'Ranking Exercise'[FIRST_NAME] )
var vCurrentEmpRank =
MAXX(
FILTER(
vEmpsWithRanks,
'Ranking Exercise'[FIRST_NAME] = vCurrentEmp
),
[@EmpRank]
)
var vEmpsWithSameRank =
FILTER(
vEmpsWithRanks,
[@EmpRank] = vCurrentEmpRank
)
var vThereAreOthersWithSameRank =
COUNTROWS( vEmpsWithSameRank ) > 1
var vResult =
if( not vThereAreOthersWithSameRank,
vCurrentEmpRank,

// Rank these others with the current one
// based on days with company where a
// lower rank means shorter period with
// the company.

vCurrentEmpRank - 1 +
RANKX(
vEmpsWithSameRank,
[Tenure Days],,
ASC
)

)
RETURN
vResult
)

EVALUATE
SUMMARIZECOLUMNS(
'Ranking Exercise'[FIRST_NAME],
"Total Sales", [Total Sales],
"Tenure Days", [Tenure Days],
"Employee Rank", [Employee Rank]
)
ORDER BY
[Employee Rank],
[Total Sales] desc,
[Tenure Days] desc``````

The code above is a DAX query that demonstrates how to construct a ranking measure that satisfies your requirements. Out of this, it's easy to just write the measure in PBI. Actually, it's already been written. It's 'Ranking Exercise'[Employee Rank]. You just have to adjust the names of some objects.

Announcements