Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How to bypass filter using ALLEXCEPT but used inside RANKX and CALCULATE

This is my dataset:

Seller NameWeekendWeek RankSales
Ben28/12/2019440
Tom28/12/2019430
Jason28/12/2019410
Clair28/12/2019420
Ben4/01/2020310
Tom4/01/2020320
Jason4/01/2020310
Clair4/01/2020330
Ben11/01/2020220
Tom11/01/2020230
Jason11/01/2020220
Clair11/01/2020230
Ben18/01/2020120
Tom18/01/2020110
Jason18/01/202010
Clair18/01/2020120

 

I want to find the ranking of each seller based on the sum of their sales for the current fortnight, and then a ranking based on the sum of their sales for the previous fortnight. Eg. my desired output table is:

 

Seller NameCurrent fortnight sales rankPrevious fortnight sales rank
Ben21
Tom33
Jason44
Clair12

 

The tricky part is there is a filter on the table which limits the weekends to the 2 most recent weeks. This is compulsory because there are other things in the table which MUST BE reported only for the 2 most recent weeks. So I need to bypass this filter to get the previous fortnight sales rank. 


I have created a measure for Current fortnight sales rank which works fine:

Current fortnight sales rank = 
RANKX(
   ALLSELECTED(Table1[Seller Name]),
   CALCULATE(SUM(Table1[Sales]),Table1[Week Rank]<3))
 
But my previous fortnight sales rank is not working....
 
Previous fortnight sales rank = 
RANKX(
    ALLSELECTED(Table1[Seller Name]),
    CALCULATE(SUM(Table1[Sales]),ALLEXCEPT(Table1,Table1[Seller Name]),Table1[Week Rank]<5&&Table1[Week Rank]>2)
)
 
My previous fortnight sales rank is giving me funny ranking that are incorrect.
 
Any help would be appreciated.......
 
 
  • Based on your data, the following seems to work:

     

    Previous Fortnight Sales Rank =
    RANKX(
        ALLSELECTED( Seller[Seller Name] ),
        CALCULATE(
            SUM( Seller[Sales] ),
            Seller[Week Rank] = 3 || Seller[Week Rank] = 4
        ),
        ,
        DESC,
        DENSE
    )

    Everyone has 50 except Jason, so it is 1,1,1,4, but by using the DENSE option, it becomes 1,1,1,2 where 2 & 3 are not skipped.

2 Replies