Forum Discussion

Arpit_Jain's avatar
Arpit_Jain
Frequent Visitor
4 years ago
Solved

Rankx function for period group

Hi all, I' working with rankx function. My ask is to get, lets say, top 2 ranks across the selected time period.

 

Lets say below is my data -

BrandSalesPeriodQuarter Period
A30Jan'211Q21
A12Feb'211Q21
A14Mar'211Q21
B16Jan'211Q21
B18Feb'211Q21
B20Mar'211Q21
C22Jan'211Q21
C24Feb'211Q21
C26Mar'211Q21
D28Jan'211Q21
D30Feb'211Q21
D32Mar'211Q21
A10Apr'212Q21
............

 

 

and I would like to display something like this -

BrandPeriodQuarter PeriodRank
AFeb'211Q21 
AJan'211Q21 
AMar'211Q21 
BFeb'211Q213
BJan'211Q213
BMar'211Q213
CFeb'211Q212
CJan'211Q212
CMar'211Q212
DFeb'211Q211
DJan'211Q211
DMar'211Q211

 

In short, I would like all of my monthly period to have same rank as the quarter.

 

What I tried: calculate(if(rankx(all('Table'[brands]), 'Table'[sales])<=2, rankx(all('Table'[brands]), 'Table'[sales]))

 

Hope I was able to simplify my actual problem to a point.

  • Hi Arpit_Jain 

     

    Avantika-Thakur 's solution is helpful. In addition, if you want to get the top 2 ranks in every quarter period, you can add Quarter Period to ALLEXCEPT function too. 

    Rank = 
    VAR _rank = RANKX(ALL('Table1'[Brand]),CALCULATE(SUM('Table1'[Sales]),ALLEXCEPT('Table1','Table1'[Brand],Table1[Quarter Period])))
    RETURN
    IF(_rank<=2, _rank, BLANK())

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

2 Replies

  • Hi Arpit_Jain ,

    You can try using the below measure -

    RANKX(ALL('Table '[Brand]),calculate(SUM('Table'[Sales]),ALLEXCEPT('Table','Table '[Brand])))
     
    Hope this helps!
     
    Thanks!
    Avantika
  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi Arpit_Jain 

     

    Avantika-Thakur 's solution is helpful. In addition, if you want to get the top 2 ranks in every quarter period, you can add Quarter Period to ALLEXCEPT function too. 

    Rank = 
    VAR _rank = RANKX(ALL('Table1'[Brand]),CALCULATE(SUM('Table1'[Sales]),ALLEXCEPT('Table1','Table1'[Brand],Table1[Quarter Period])))
    RETURN
    IF(_rank<=2, _rank, BLANK())

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.