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
paresh
Frequent Visitor

Getting TOP n Items in a Table/chart

I have gone through the forum and have found many queries which pertain to the above topic (have searched on TopN and RankX). I have tried all of them and have not been able to come up with the correct result. 

I will try and put my problem in as simple terms as I can. So here goes.

 

I am trying to create some analytics for a restaurant. I want to show the Top 10 items which were sold (by quantity) withing a given date range (dates being select from a slicer - picking years or months)

 

So I created a measure for summing up my quantities

 

Msr_SaleQty = sum('sales'[quantity])

 

Next I created another measure to get the Rank

 

Msr_Rank_by_qty = RANKX(ALL('sales'[item]),[msr_saleqty])

 

So far so good.

Now I create a table visualization and add the item, quantity and the Rank in it. ( i have just done Top 3 in the example)

 

 

item ranking.JPG

This works perfectly.

However If I add a month column into this table, I get the ranking for each month. So If I have selected 2 months, then I will get 6 rows.

item ranking2.JPG

 

But I just want the composite ranking within whatever periods I have selected.

 

I have looked at the following article

RANKX-apalooza

Tried to change my ranking measure according to this 

Created another measure as follows

 

Msr_Rank_by_qty1 = RANKX(ALLSELECTED('sales'),CALCULATE(sum('sales'[quantity])))

Now the results are worse..

 

10 REPLIES 10

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.