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

Divide a subcategory by the qty of a higher category

Dear Power BI Pros,

 

I have a problem that I cannot find a measure that calculates the material costs per quantity of finished product.

I tried:


Costs Material p Finished Good = DIVIDE(SUM(Facts[Costs Material]),SUM(Facts[Qty Finished Product]))

but I am missing the link between materials used and the quantity of the finished product (the production order number) in the formula.

 

I have a fact table with Production order numbers, finished products numbers, their quantity and costs, as well as the material used to produce these finished products, also their quantities (so the quantities of the materials used) and the costs.

A production order always has several lines. One for the product that was produced (the finished product and the quantity) and then the materials that were used.

 

I know would like to divide the material costs through the quantity of the finished product to get the costs per finished product.

 

Here is the visual that I would like to finish:

 

Test Production - Power BI Desktop.png

 

 

Here is the star scheme and the fact table:

Test Production-Star schema - Power BI Desktop.pngTest Production - Table - Power BI Desktop.png

 
Can someone help?
 
Thanks,
Smeek
1 ACCEPTED SOLUTION

Here's the file with the solution that I was talking about above...

 

https://1drv.ms/u/s!ApyQEauTSLtOgY8soLaHD-juLe_hYw?e=iGqXso

 

View solution in original post

7 REPLIES 7

Here goes, I hope that helps:

Prod. Order NoFinished ProductCosts Finished ProductQty Finished ProductMaterial NoQty MterialCosts Material
PON-400   MN-38410
PON-400   MN-38320
PON-400   MN-386421
PON-400   MN-35511.709
PON-400   MN-1093138
PON-400FP-31.8165   
PON-401   MN-38410
PON-401   MN-38350
PON-401   MN-386121
PON-401   MN-35511.709
PON-401   MN-1093138
PON-401FP-31.8162   
PON-410   MN-38480
PON-410   MN-38390
PON-410   MN-386921
PON-410   MN-35591.709
PON-410   MN-1093938
PON-410FP-31.8207   

 

Smeek
Frequent Visitor

I managed to change the calculation to:

Costs Material p Finished Good = DIVIDE(SUM(Facts[Costs Material]),CALCULATE(Sum(Facts[Qty Finished Product]),ALLEXCEPT(Facts,Facts[Production Order No])))
 
This kind of works, as long as I take the Production Order Number from the Fact table and not from the Dimension table. 
Test Production - Formula - Power BI Desktop.png
How can I connect the formula to the Dimension table? Or is there another way to calculate teh material costs on basis of the Finished Product Quantity?
 
Thanks for any help
 
Anonymous
Not applicable

OK. I've got a pbix file with the solution. Please bear with me as I'm at work right now and can't put the file on a shared drive... I'll do it in a bit.

Here's the file with the solution that I was talking about above...

 

https://1drv.ms/u/s!ApyQEauTSLtOgY8soLaHD-juLe_hYw?e=iGqXso

 

Thanks a lot for your help and the file. 

I guess the main message is that I need to split the fact table into two, one for the finished products and one for the materials.

Or get my fact table cleaned up so the finished product ID is entered on the same line as the material numbers. 

 

Since it was quicker so slit the fact table, I tried it on the original data and it works 🙂

 

Thanks for your help!

 

Anonymous
Not applicable

Create 3 dimensions:

> Order, Product, Material

Create 2 fact tables:

> Order|Product|Prod Qty|Prod Cost

> Order|Product|Material|Material Qty|Material Cost

Join the dims to the facts (1:* with the standard one-way filtering). This way you will have isolated all the dims you need and the fact tables capture 2 processes: the manufacturing of products and the bill of materials needed to manufacture the products. This model will be simpler to calculate what you want. The fact tables will all be hidden since you should NEVER slice by columns in a fact table. Only via dimensions.

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