Forum Discussion

rauerfc's avatar
rauerfc
Frequent Visitor
5 years ago
Solved

RANKX returning variable, TOP 1, 2, 3, 4

I have a table that has sales by month, account manager, and MRK.

I need that the measure returns the TOP 1 selling MRK and another one for 2, 3, and 4.

Output = 130 or 40 or 110

Each measure will be used in 4x charts, each one for the TOP 1,2,3,4, and this could vary by Account Manager.

Each Acc Manager could have differents TOP 1, 2, 3, 4 consequently, different charts.

Sample of dataset:

 

MRKManagerMonthQuantity Sales
10921Mar-219
10952Mar-212
40921Mar-2122
40952Mar-2153
404147Mar-2138
4024829Mar-216
1104147Mar-210
130951Mar-21210
150943Mar-2158
150947Mar-21307
150951Mar-21324
150952Mar-2126
17041687Mar-21129
170921Mar-212
170922Mar-2112
170923Mar-21201
170924Mar-2185
170943Mar-218
170947Mar-2128
170951Mar-21221
170952Mar-2126
1703627Mar-2150
1704147Mar-2152
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi rauerfc ,

     

    Please try the following formula to create measures :

    sum = CALCULATE(SUM('Table'[Quantity Sales]),ALLEXCEPT('Table','Table'[MRK]))
    rank = RANKX(FILTER(ALL('Table'),'Table'[Manager]=MAX('Table'[Manager])),[sum],,DESC,Dense) 

    If you want to separately get the rank value , you could use this:

    Top 1 MRK = CALCULATE(MAX('Table'[MRK]),FILTER('Table',[rank]=1))

    The final output is shown below:

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

8 Replies

  • What result are you expecting.  Explain the question clearly and show the expected result.

    • rauerfc's avatar
      rauerfc
      Frequent Visitor

      I need one measure that's going to calculate the TOP 1 selling MRK.

      So if I select this Acc. Manager, the best-selling MRK will be 130.

      And another measure to return the second best, third best, and fourth-best.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi rauerfc ,

     

    Please try the following formula to create measures :

    sum = CALCULATE(SUM('Table'[Quantity Sales]),ALLEXCEPT('Table','Table'[MRK]))
    rank = RANKX(FILTER(ALL('Table'),'Table'[Manager]=MAX('Table'[Manager])),[sum],,DESC,Dense) 

    If you want to separately get the rank value , you could use this:

    Top 1 MRK = CALCULATE(MAX('Table'[MRK]),FILTER('Table',[rank]=1))

    The final output is shown below:

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