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

Sum of sales of top 10 products each year

Hi All,

 

I have columns as price, products, year..Now, i want to calculate sum of sales of top 10 products for eacyh year. How do i do that?Can anyone provide the correct dax measure to be used.

 

TIA

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

@Anonymous 

It really depends on what you wish to display in your visuals. If it is just the sum fo the top 10, then the function TOPN is probably your best bet. Otherwise you have options of using RANKX or even just the filter pane.

 

Here are some examples for a simple dataset with values per item (in this case for the top 3 Items in terms of "Actuals"):

1) displaying the sum of the top 3 Items per year in a table/matrix:

Top 3 Items table.JPG

With these measures: 

Sum of Actuals = SUM('Data Table'[Actuals])

 

Top 3 per year = SUMX(TOPN(3; ALLSELECTED('Item'[Item]); [Sum of Actuals]; DESC); [Sum of Actuals])

 

 

2) or you can use the filter pane to show the top N values (in this case top 3):

TopN filter pane.JPG

 

3) or you can use rhe RANKX function:

RankX Actuals (Item) = 
VAR calc = RANKX(ALLSELECTED('Item'[Item]);[Sum of Actuals];; DESC;Dense)
RETURN
IF(ISINSCOPE('Item'[Item]); calc; BLANK())

 

and then

Top 3 Items using RANKX = 
VAR calctotal = CALCULATE([Sum of Actuals]; 
                FILTER('Item';
                [RankX Actuals (Item)]<4))
VAR top3 = IF([RankX Actuals (Item)]<4; [Sum of Actuals]; BLANK())
Return
IF(ISINSCOPE('Item'[Item]); top3; calctotal)

To get you this

Top 3 RankX.JPG

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

1 REPLY 1
PaulDBrown
Community Champion
Community Champion

@Anonymous 

It really depends on what you wish to display in your visuals. If it is just the sum fo the top 10, then the function TOPN is probably your best bet. Otherwise you have options of using RANKX or even just the filter pane.

 

Here are some examples for a simple dataset with values per item (in this case for the top 3 Items in terms of "Actuals"):

1) displaying the sum of the top 3 Items per year in a table/matrix:

Top 3 Items table.JPG

With these measures: 

Sum of Actuals = SUM('Data Table'[Actuals])

 

Top 3 per year = SUMX(TOPN(3; ALLSELECTED('Item'[Item]); [Sum of Actuals]; DESC); [Sum of Actuals])

 

 

2) or you can use the filter pane to show the top N values (in this case top 3):

TopN filter pane.JPG

 

3) or you can use rhe RANKX function:

RankX Actuals (Item) = 
VAR calc = RANKX(ALLSELECTED('Item'[Item]);[Sum of Actuals];; DESC;Dense)
RETURN
IF(ISINSCOPE('Item'[Item]); calc; BLANK())

 

and then

Top 3 Items using RANKX = 
VAR calctotal = CALCULATE([Sum of Actuals]; 
                FILTER('Item';
                [RankX Actuals (Item)]<4))
VAR top3 = IF([RankX Actuals (Item)]<4; [Sum of Actuals]; BLANK())
Return
IF(ISINSCOPE('Item'[Item]); top3; calctotal)

To get you this

Top 3 RankX.JPG

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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.