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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
BeeBeeJay
Frequent Visitor

RANKX across groups - dense rank not working as expected

I have a table of sales quantity by product, and when I create a ranking measure showing most sold to least sold it works fine.  When I then group my products into categories and show the rank by category, the ranking is no longer dense ...... ?

 

Sample Table:

tblSales = DATATABLE("Row ID", INTEGER, "Product", STRING, "Qty Sold", INTEGER, { {1, "Coffee", 100 }, {2, "Tea", 120 }, {3, "Fruit Juice", 75 }, {4, "Sandwich", 50 }, {5, "Pizza", 20} })

 

Add measure:

Sales Rank = RANKX(ALL(tblSales), CALCULATE(SUM(tblSales[Qty Sold]) ),,DESC,Dense)

 

If tyou display this information in a table visual it all works as expected with tea ranked first for sales and pizza ranked last.

 

Next, add a Category Group into the table grouping "Sandwich" and "Pizza" into "Food", and "Tea", "Coffee", and "Fruit Juice" into "Drinks".

 

Add the "Category" field to the table, everything is still fine.

 

Remove "Product" field from the table, and the table collapses to the two Category rows - food and drink - with the correct sum of Qty Sold, but the ranking instead of being 1 and 2 is 1 and 4 - and I have no idea why.  

pbi.pngAny help much appreciated.

 

1 ACCEPTED SOLUTION
BeeBeeJay
Frequent Visitor

Changing the measure to:  

 

 

Sales Rank = RANKX(ALL(tblSales[Category]), CALCULATE(SUM(tblSales[Qty Sold]) ),,DESC,Dense)

 

Has fixed the issue.  (Still trying to work out why)

 

Got the solution from this excellent post.

 

https://powerpivotpro.com/2015/06/rankx-apalooza-within-and-across-groups-with-filters-etc/

 

 

View solution in original post

3 REPLIES 3
BeeBeeJay
Frequent Visitor

Changing the measure to:  

 

 

Sales Rank = RANKX(ALL(tblSales[Category]), CALCULATE(SUM(tblSales[Qty Sold]) ),,DESC,Dense)

 

Has fixed the issue.  (Still trying to work out why)

 

Got the solution from this excellent post.

 

https://powerpivotpro.com/2015/06/rankx-apalooza-within-and-across-groups-with-filters-etc/

 

 

Zubair_Muhammad
Community Champion
Community Champion

@BeeBeeJay

 

Try using ALLSELECTED

 

RANKX(ALLSELECTED(tblSales)

Thanks for the suggestion, but this didn't work for me.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.