Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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.......
 
 
1 ACCEPTED SOLUTION
edhans
Super User
Super User

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.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

2 REPLIES 2
edhans
Super User
Super User

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.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
amitchandak
Super User
Super User

Please find the solution at

https://www.dropbox.com/s/0ec5u2nhxuo22eb/weeklysellerRank.pbix?dl=0

 

You might have to do a small change to adjust the fortnight calculations

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.