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

Top N products sold per product category

Hi, 

 

I'm totally new with Power BI and already ran in trouble when trying to create this simple table.

 

I need to create a table which has top 20 products sold for each product category. For example, if I have three product categories which have 100 products each, I need to create a table which has 60 products in total grouped in 3 categories (3 categories x top 20 products).

 

Could someone give some pointers how to solve this? 

 

Br, Pekka

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @plaa,

 

If I understand you correctly, you should be able to follow steps below to create the table which has top 20 products sold for each product category. Smiley Happy

 

1. Use the formula below to create a measure to calculate Total Sales.

Total Sales = SUM(Sales[Revenue])

m1.PNG

 

2. Use the formula below to create a calculate column in Product table to rank product sold for each product category.

Rank =
RANKX (
    ALLEXCEPT ( Products, Products[Category] ),
    [Total Sales],
    ,
    DESC,
    DENSE
)

c1.PNG

 

3. Then you should be able to use the formula below to create the table.

Table = 
SELECTCOLUMNS (
    FILTER ( Products, Products[Rank] <= 20 ),
    "Category", Products[Category],
    "Product", Products[Product],
    "Rank", Products[Rank]
)

t1.PNG

 

Regards

View solution in original post

1 REPLY 1
v-ljerr-msft
Employee
Employee

Hi @plaa,

 

If I understand you correctly, you should be able to follow steps below to create the table which has top 20 products sold for each product category. Smiley Happy

 

1. Use the formula below to create a measure to calculate Total Sales.

Total Sales = SUM(Sales[Revenue])

m1.PNG

 

2. Use the formula below to create a calculate column in Product table to rank product sold for each product category.

Rank =
RANKX (
    ALLEXCEPT ( Products, Products[Category] ),
    [Total Sales],
    ,
    DESC,
    DENSE
)

c1.PNG

 

3. Then you should be able to use the formula below to create the table.

Table = 
SELECTCOLUMNS (
    FILTER ( Products, Products[Rank] <= 20 ),
    "Category", Products[Category],
    "Product", Products[Product],
    "Rank", Products[Rank]
)

t1.PNG

 

Regards

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.

Top Solution Authors