Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
JNelson
Helper II
Helper II

DAX to Calculate Cost of Ingredients

Hello,

 

I've read through similar questions to mine but I can't quite get them to work for my data.

I have three tables:

1. Sales (includes SKU and Qty)

2. Components (Includes SKU and the 15 different components/ingredients that make up the product) there are 65 different products.

3. Cost (Has the components/ingredients and cost of each).

 

I'm having difficulty calculating the cost per sale. I've done a workaround but there must be a simpler way. I've gone the (super) long way around and done:

CostPerSale=SUMX(NATURALINNERJOIN(Sales,Components),[Qty]*Components[Ingredient1]*SUM(Cost[Ingredient1])) + 

SUMX(NATURALINNERJOIN(Sales,Components),[Qty]*Components[Ingredient2]*SUM(Cost[Ingredient2])) + 

SUMX(NATURALINNERJOIN(Sales,Components),[Qty]*Components[Ingredient3]*SUM(Cost[Ingredient3]))......... until I get to ingredient 15!

 

Please help 🙂

 

Thank you!

6 REPLIES 6

Hey, you have to reformat your COMPONENTS table structure to:

 

SKUComponentShare
134786IngA0.04
134786IngB0.3
134786IngC0
134786IngD0.08
134786IngE0.29
134786IngF0.2
134786IngG0.09
134786IngH0

 

The measures would be

 

 

Cost of Ingredients = 

VAR _Share = MAX(Misc[Share])
VAR _Cost = MAX(Cost[Ingredient Cost])
VAR _Qty = MAX(Sales[Qty])

return _Share * _Cost * _Qty

 

 

 

Total Cost of Ingredients = SUMX(VALUES(Misc), [Cost of Ingredients])

 

 

Then you put Sales[Customer] and [Total Cost of Ingredients] in a Table

 

Power BI.PNG

 

You can download the PBIX file here: https://milanpasschier2.s3.eu-central-1.amazonaws.com/Com+1.pbix

 

Please mark my answer as the solution if it fits your needs.

 

All the best,

 

Milan

Whitewater100
Solution Sage
Solution Sage

Hi:

Perhaps you can have a several tables:

Dates - Date, Month, Year, Week No., YR-MO

Share_of_Cost = Item, Component, Share (This table woul be longer as each items compents and share is set to 100%

Material_Cost = Component, Price

 

Once these tables are in place a more streamlined measure can work. If you have data for example, that would be great.

 

Thanks..

Anonymous
Not applicable

Hi @JNelson ,

What is your desired output?  It seems you need to calculate the result by "the 65 different products." If so , maybe your formula is the only one. If I have misunderstood your meaning, please provide your desired output with more details.

 

How to Get Your Question Answered Quickly 

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous 

Essentially I need to look up the SKU purchased and then carry out a SUMPRODUCT on the components of that SKU against the cost of the components. My problem is that they are all in different tables.

 

For example the cost of Max Tom's purchase (SKU 134786) would be:

(0.04 * 1250) + (0.30 * 42.08) + (0.00 * 42.08) + (0.08 * 45.08) + (0.29 * 45.08) + (0.20 * 431.00) + (0.09 * 27.78) + (0.00 * 25.50) = $168.00

Then multiply it the QTY = $168 * 3 = $504.01

 

The comment around the 65 products is that there are 65 prodcts that the customer can choose from.

 

Thanks

 

JNelson
Helper II
Helper II

Hi @DimaMD ,

 

Thank you for your reply. The information is sensitive. Will the below tables be enough to get assistance?

 

SALES TABLE

CustomerSKU QtyTotal Sell Price
Bob Smith112668 4$495.00
Bob Smith112670 2$217.00
Jane Brown112676 56$5,098.00
Max Tom134786 3$475.00

 

COMPONENTS

SKU IngAIngBIngCIngDIngEIngFIngGIngH
112668 0.250.100.030.050.070.300.020.18
112670 0.050.150.700.000.000.020.060.02
112676 0.400.000.000.050.500.050.000.00
134786 0.040.300.000.080.290.200.090.00

 

COST

ComponentIngredient Cost
Ing A$1250.00
IngB$42.08
IngC$42.08
IngD$45.08
IngE$45.08
IngF$431.00
IngG$27.78
IngH$25.50
DimaMD
Solution Sage
Solution Sage

Hi @JNelson Please provide a sample of your data in a pbix file or spreadsheet, thank you


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.