Forum Discussion

CEllis's avatar
CEllis
Resolver I
2 years ago
Solved

Ranking using group and sum

Afternoon,

 

Is it possible to use a DAX statment to do ranking over a single table that resets at each change in grouping.

 

Source_Table

IdSubjectCycleResult
10Art134
11Art112
10Biology138
11Biology110
10French12
11French124
10Art223
11Art215
10Biology222
11Biology234
10French245
11French210

 

Outcome - The RANK column shows which id has the lowest figure in the subject,cycle group.

IdSubjectCycleResultRANK
10Art1342
11Art1121
10Biology1382
11Biology1101
10French121
11French1242
10Art2232
11Art2151
10Biology2221
11Biology2342
10French2452
11French2101

 

Many thanks

 

Chris

  • CEllis , You can try below DAX

     

    RANK =
    RANKX(
    FILTER(
    Source_Table,
    Source_Table[Subject] = EARLIER(Source_Table[Subject]) &&
    Source_Table[Cycle] = EARLIER(Source_Table[Cycle])
    ),
    Source_Table[Result],
    ,
    ASC
    )

4 Replies

  • CEllis , You can try below DAX

     

    RANK =
    RANKX(
    FILTER(
    Source_Table,
    Source_Table[Subject] = EARLIER(Source_Table[Subject]) &&
    Source_Table[Cycle] = EARLIER(Source_Table[Cycle])
    ),
    Source_Table[Result],
    ,
    ASC
    )

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for the reply from bhanu_gautam , please allow me to provide another insight: 

    Hi  CEllis ,

     

    Here are the steps you can follow:

    1. In Power Query – Transform -- Group.

    Advanced – [Subject] and [Cycle]

    Operation – All Rows

    2. Add Column – Custom Column – Enter code.

    Table.AddIndexColumn(
            Table.Sort([Row],{{"Result",
            Order.Ascending}}), "Row Rank",1,1)

    3. Select [Custom] – [Rank] ,[ID] and [Row Rank].

    4. Remove – [Row].

    5. Result:

     

     

    Best Regards,

    Liu Yang

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

    • CEllis's avatar
      CEllis
      Resolver I

      Anonymous bhanu_gautam Thankyou both for your support its much appreciated.

       

      I can get the Anonymous to work but can bhanu_gautam be used in combination because I need to allow the same values to have the same rank number.