Forum Discussion

CamIAm88's avatar
CamIAm88
Regular Visitor
3 years ago
Solved

Help with ranking Employees for each group using RANKX

I have a dashboard created where the user selects an employee and a table displays metrics for all the work groups worked by that employee. I would like to add a column to the table on my dashboard that displays how that KPI ranks amongst all other users for that group. Please note, I would like to create a measure since my model is large and I am running low on space.

 

Below are examples of my existing data and the DAX I'm currently using to calculate the tranking:

 

DAX:

 

 

 

RankEmployee = 
RANKX(
    FILTER(
        ALL(Table_1[Employee_A], (Table_1[Work_Group]),
        Table_1[Work_Group] = MAX(Table_1[Work_Group])
        ),
        CALCULATE( SUM( Table_1[KPI]) ) -- Note actual calculate simplified for example
 	)

 

 

 

Example of Existing Table (3 columns, Employee, Work_Group, KPI):

 

EmployeeWork_GroupKPI
AWork Type A100
AWork Type B10
AWork Type C50
BWork Type A90
BWork Type B45
BWork Type C1
CWork Type A80
CWork Type B60

 

Example of the desired outcome for the table in the dashboard (4 columns, Employee, Work_Group, KPI, Rank):

 

EmployeeWork_GroupKPIRank
AWork Type A1001
AWork Type B103
AWork Type C501
BWork Type A902
BWork Type B452
BWork Type C12
CWork Type A803
CWork Type B601

 

 

  • Hi CamIAm88 ,

     

    Please try:

    RankEmployee =
    VAR _a =
        ADDCOLUMNS (
            ALL ( Table_1 ),
            "Rank",
                RANKX (
                    FILTER ( ALL ( Table_1 ), [Work_Group] = EARLIER ( Table_1[Work_Group] ) ),
                    [KPI]
                )
        )
    RETURN
        MAXX (
            FILTER (
                _a,
                [Employee] = MAX ( 'Table_1'[Employee] )
                    && [Work_Group] = MAX ( 'Table_1'[Work_Group] )
            ),
            [Rank]
        )
    

     

    Final output:

    Best Regards,

    Jianbo Li

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • CamIAm88 , The measure you provided should work with small change

     

    RankEmployee =
    RANKX(
    FILTER(
    ALL(Table_1[Employee_A], (Table_1[Work_Group]),
    Table_1[Work_Group] = MAX(Table_1[Work_Group])
    )),
    CALCULATE( SUM( Table_1[KPI]) ) -- Note actual calculate simplified for example
    )

    • CamIAm88's avatar
      CamIAm88
      Regular Visitor

      Thank you for your quick response Amit. There was a typo in my DAX after rewriting it for the post but where I'm having the issue is with the results. The DAX designates a rank 1 to all work groups.

       

      I would like for the measure to compare the KPI for the selected employee to that of all employees per Work_Group. 

  • Hi CamIAm88 ,

     

    Please try:

    RankEmployee =
    VAR _a =
        ADDCOLUMNS (
            ALL ( Table_1 ),
            "Rank",
                RANKX (
                    FILTER ( ALL ( Table_1 ), [Work_Group] = EARLIER ( Table_1[Work_Group] ) ),
                    [KPI]
                )
        )
    RETURN
        MAXX (
            FILTER (
                _a,
                [Employee] = MAX ( 'Table_1'[Employee] )
                    && [Work_Group] = MAX ( 'Table_1'[Work_Group] )
            ),
            [Rank]
        )
    

     

    Final output:

    Best Regards,

    Jianbo Li

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.