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
Johan
Advocate II
Advocate II

Show items that make up x% of the sales

Hi,

 

I'm looking for the dax to show only the items (and their quantities) that make up e.g. 60% of the sales.
Example

item table

ItemID,Item name
1,Parfume
2,Shower foam
3,After shave
4,Soap

 

sales table

ItemID,Store,Qty.
1,A,110
1,B,310
1,C,510
2,A,120
2,C,320
3,A,130
3,B,230
3,C,330
3,D,430
4,A,240
4,B,440

 

Outcome should be

After shave  1120 qty

Parfume      930 qty

 

Anyone has an idea?

 

Thanks,

Johan

1 ACCEPTED SOLUTION

Hi @Johan ,

 

Based on the option given by @marcorusso  create the following calculated columns on your items table:

 

% total = CALCULATE(SUM(Sales[Qty]);RELATEDTABLE(Sales))/SUM(Sales[Qty])

Ranking = RANKX('Item';CALCULATE(SUM(Sales[Qty])))


Cumulative % = CALCULATE(SUM('Item'[% total]);ALL('Item');'Item'[Ranking] <= EARLIER('Item'[Ranking]))

Then use the following measure:

Final_Result = IF(SUM('Item'[Cumulative %]) <= [% Products Value];[Total_Qty];BLANK())

The previous measure reference below will not be used so if you want you can deleted them:

  • Cumulative%
  • Cumulative_qty
  • Item_rank
  • Qty_All_Item

 

See file attach.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

8 REPLIES 8
MFelix
Super User
Super User

Hi @Johan ,

 

Need to create a pareto kind calculation

 

Following this blog post and making some additional changes you can do the following.

 

so you can have the cumulated percentage create the following measures:

Total_Qty = SUM(Sales[Qty])

Qty_All_Item = CALCULATE([TotalQty];ALL('Item'[Item Name]))

Item_Rank = RANKX(ALL('Item'[Item Name]);[Total_Qty])

Cumulative_Qty = SUMX(TOPN([Item_Rank];ALL('Item'[Item Name]);[Total_Qty]);[Total_Qty])


Cumulative_%_Qty = DIVIDE([Cumulative_Qty];[Qty_All_Item];BLANK())


Filter_Result = IF([Cumulative_%_Qty] <= 0,6; [Total_Qty];BLANK())

 

If you want you can also add a parameter table that defines the % for wich you want to show products change last measure by this one:

 

Final_Result = IF([Cumulative_%_Qty] <= [% Products Value]; [Total_Qty];BLANK())

Now place on a table the Item name and the Final result measure:

cumulative%.gif

 

 

Check attach PBIX.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Excellent solutions, my compliments.

Only thing is that my sales table has 17mln rows and the sumx is eating the memory. Any change to avoid that? For the rest it's exactly what I'm looking for. Thanks.

Hi @Johan ,

 

Based on the option given by @marcorusso  create the following calculated columns on your items table:

 

% total = CALCULATE(SUM(Sales[Qty]);RELATEDTABLE(Sales))/SUM(Sales[Qty])

Ranking = RANKX('Item';CALCULATE(SUM(Sales[Qty])))


Cumulative % = CALCULATE(SUM('Item'[% total]);ALL('Item');'Item'[Ranking] <= EARLIER('Item'[Ranking]))

Then use the following measure:

Final_Result = IF(SUM('Item'[Cumulative %]) <= [% Products Value];[Total_Qty];BLANK())

The previous measure reference below will not be used so if you want you can deleted them:

  • Cumulative%
  • Cumulative_qty
  • Item_rank
  • Qty_All_Item

 

See file attach.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks both for you input and solution.

I have now precalculated the accumulated sales in the datawarehouse, and the pareto-dax in the report and that works fine. 

Hi @Johan

 

 

Didn't realize size of your data.

 

I was reading about performance on SQLBI site and I'm reaching to @marcorusso that wrote an article about this.

 

https://www.sqlbi.com/articles/optimizing-dax-expressions-involving-multiple-measures/

 

@marcorusso can you check how the measures can be optimize or if this is the best option?

 

Thank you. 

 

Regards

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



You should precalculate the cumulated value to avoid the memory materialization - but you loose the flexibility of having the dynamic calculation now that responds to any other filter/slicer in the report.

 

Hi @marcorusso ,

 

Thank you for the response, so if I understand correctly and looking at the size of the model a good alternative is to make a calculated table or add a calculated column on the items table with the sum of sales and/or percentage of total sales?

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Correct!

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.