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 calculate the sales of the top N in a dataset?

Hello,

 

Within PowerBi, is there a way to caculate the total sales for the Top N of a dataset? I would like to create a calculation that says, for example, that the top 10 products sold make up x% of total sales. 

 

Regards,

Alex

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

Please share some sample data with same data structure for test to coding formula.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Hi,

 

Not sure if this is the most efficient approach, but I got it up and running. I used sample data from the PowerBI Dashboard in a Day assets. The assumption with this solution is that you leverage some sort of Sales fact table, as well as a Product dimension table. 

 

1. Since there is one row per product in the dimension, my first step was to add a calculated column to the Product dimension that represents the total revenue for each product:

 

Revenue = SUMX(FILTER(Sales,'Product'[ProductID] = Sales[ProductID]), Sales[Revenue])
 
2. I then created another calculated column to represent the rank of products by revenue:
 
Rank = RANKX('Product','Product'[Revenue])
 
3. At that point, you can just create a calculated measure for your % calc:
 
Top 10 % = [Top 10 Revenue] / SUM(Sales[Revenue])
 
I'm sure there's a way to do this all within the same fact table, but I just had the thought to create new columns in the dimension since it was quick. I attached an image below demonstrating the results. Let me know if this helps.
 
Ben
 
Top 10 % Sales by Product Calc.PNG

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.