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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

How can I remove filters from a RANKX function in powerbi?

I've been struggling with removing filters from the rank calculation in dax.

I have a sample table with units per store for individual items broken out by their respective Department, Category, Sub-Category, Parent Company, and Parent Brand.

 

     testrank = RANKX(ALLSELECTED(Sales), CALCULATE(SUM(Sales[UnitsPerStore])),,ASC)

akaska_0-1636673279528.png


As you can see from the above, the rank is working how I would expect. However, I want the end user to be able to filter to a particular brand they are curious about without affecting the rank. Below I filtered to ParentBrand of Carvel. The rank automatically changed based on the visual:

akaska_1-1636673388229.png


So the only filters that the end user applies that I want to affect the calculation are Department, Category, and Subcategory. So if someone looks up a particular UPC for example, they would see the rank of that upc based on the selection of the department/category/subcategory.

I have tested a couple methods and feel as if I"m getting close:

method1 = RANKX(FILTER(ALL(Sales), Sales[CorporateDepartment] = max(Sales[CorporateDepartment]) && Sales[Category] = max(Sales[Category]) && Sales[SubCategory]=max(Sales[SubCategory])), CALCULATE(MAX(Sales[UnitsPerStore])),, ASC,Dense)

 

method2 = RANKX(ALLEXCEPT(Sales, Sales[CorporateDepartment], Sales[Category], Sales[SubCategory]), CALCULATE(Sum(Sales[UnitsPerStore])),,ASC,Dense)

akaska_2-1636673729582.png


So with both Methods, the filtering issue was resolved. If I filtered to a brand, it wouldn't affect the original ranking the item had based on what category or subcategory I had selected. However for some reason the rankings are off. I'm seeing repeat rankings, almost as if the rank has a group by applied to it. 


Would apreciate any help!




1 ACCEPTED SOLUTION

I have a suspicion that you won't be able to get this to work without having department and category columns in a separate dimension table due to auto-exists eliminating rows that you want to keep.

 

Try creating a dimension table for those columns.

View solution in original post

8 REPLIES 8
VahidDM
Super User
Super User

HI @Anonymous 

 

Can you share a sample of your data in a table format to be able to copy and past that to PBI?

and can you add more details or a sample of the output you are looking for?

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Anonymous
Not applicable

What I'm Looking for:

Below is what the end user would see with only filtering to the ice cream and pizza Categories, they have not done any filtering outside of that. As you can see the ranking is working as it should. Please not the ranking of the Carvel Branded items: 

akaska_1-1636690454156.png

 

 

However, the end user might really be curious about the performance of the Carvel Brand for instance. So they want to filter to them so they are only looking at Carvel. However I want the ranking that was based on the selection of Ice Cream and Pizza Categories to remain the same. With the current rankx function the ranking automatically changes to whats being filtered:

 

akaska_2-1636690580032.png

 

I'd like that 1 and 2 ranking to be the 5 and 8 ranking we saw in the 1st screenshot. 

 

UPCdescriptionCorporateDepartmentCategorySubCategoryParentBrandParentCompanyUnitsPerStore
4pep pizzaGeneralPizzathin crustraguMizkan America, Inc.708
5sausage pizzaGeneralPizzathick crustcontadinaDel Monte Consumer Products553
6choc ice creamFrozenice creamchocolateblue bunnyswells ice cream485
7red pizza sauceGeneralPizzaSauceGustare VitaGustare Vita467
8Caramel DelightFrozenIce CreamNoveltyOutshineNestle Dreyers400
9Pizzaria Style Pizza SauceGeneralPizzaSaucePregoCampbell Soup Company388
10Vanilla Ice CreamFrozenIce CreamVanillaBen and JerrysBen & Jerrys367
11Cookies and Cream Ice CreamFrozenIce CreamIce Creamblue bunnyswells ice cream337
12cheese pizzaGeneralPizzathin crustraguMizkan America, Inc.437

 

Hopefully this sample data gives you what you need. Thanks for the help!

AlexisOlson
Super User
Super User

It is doing a sort of grouping. From this documentation:

"When used as a table function, ALLEXCEPT materializes all the unique combinations of the columns in the table specified in the first argument that are not listed in the following arguments. In this case, the result only has the columns of the table and ignores the expanded table."

 

Maybe if you use it not as a table argument, then it will work like you expect:

method2 =
RANKX (
    CALCULATETABLE (
        Sales,
        ALLEXCEPT (
            Sales,
            Sales[CorporateDepartment],
            Sales[Category],
            Sales[SubCategory]
        )
    ),
    CALCULATE ( SUM ( Sales[UnitsPerStore] ) ),
    ,
    ASC,
    DENSE
)
Anonymous
Not applicable

Thank you for your quick response! I think we are still having the same issue. I named your suggestion as "Method3" in the below table. It looks like the ranking is following exactly what Method 1 was doing:

akaska_0-1636676416444.png

 

I have a suspicion that you won't be able to get this to work without having department and category columns in a separate dimension table due to auto-exists eliminating rows that you want to keep.

 

Try creating a dimension table for those columns.

Anonymous
Not applicable

I will try that out! As far as the dimension table goes, would it just be a 3 column table of all the possible combinations of Department, Category, and Subcategory? Or would it be a dimension table with all the item info available (UPC, Department, Category, SubCategory, ParentBrand, and Parent Comapny)?

I was wondering if you found a solution to this issue.  I am having the exact same problem.

Generally, you do want that sort of stuff in a dimension table rather than a fact table. If you're going to create a dimension table anyway, might as well put all of the relevant columns there.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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