cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rvs Frequent Visitor
Frequent Visitor

DAX - How to get RANKX independent of filters

// Note: [Master Product] is not the key level of Product but a higher level "Parent" product
// Countrows works perfectly and retains the same Total of Category value even when used within additional Product filters

measure 'Sales'[MyCount] = 
var tbProds = 
  calculatetable(filter(all('Product'[Master Product]),[Sales]>0), ALLEXCEPT('Product','Product'[Category]))
return 
  countrows(tbProds)
  
// Rankx only works as long as no additional filters are applied
// When additional Product filters are applied (e.g. Product[Vendor]) it ranks [Master Product] within that filter not within Total Category
// Why is one function affected by filters the other not?
// How do we achieve a ranking within Category that is independent of filters?

measure 'Sales'[MyRank] =
var tbProds = 
  calculatetable(filter(all('Product'[Master Product]),[Sales]>0), ALLEXCEPT('Product','Product'[Category]))
return 
  rankx(tbProds,[Sales],,,dense)

The above snippet shows 2 measures, MyCount works as expected, MyRank does not. Hopefully the comments tell most of the story. The goal is to get a rank over Product[Category] that is constant regardless of any other Product filters. The VARs are for readability only, we get the same results without using VARs. Any ideas how to achieve this? 

2 REPLIES 2
Community Support Team
Community Support Team

Re: DAX - How to get RANKX independent of filters

@rvs ,

 

You may try ALLSELECTED.

https://community.powerbi.com/t5/Desktop/RANK-MIN-OF-SUM-grouped-by-two-fields/m-p/581289#M275025

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
rvs Frequent Visitor
Frequent Visitor

Re: DAX - How to get RANKX independent of filters

ALLSELECTED has the opposite effect to what I require. From https://docs.microsoft.com/en-us/dax/allselected-function-dax

"The ALLSELECTED function gets the context that represents all rows and columns in the query, while keeping explicit filters and contexts other than row and column filters."

I want to remove all filters except the current Product[Category] which should be what ALL() does.

I suspect this is something to do with RANKX being iterative but I dont understand it enough to explain why. I have even tried the countrows(filter(table,sales>currsales variable)) technique and that doesn't work either. Probably because of filter iterating too.

Thanks for replying though Smiley Happy 

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors