Forum Discussion
Parent-child flattening (multiple levels)
- Sep 19, 2021
I didn't dive a deep into calculations, here is only suggestion for iterations.
We keep as it is now tBOM and tCalc1.
Levels are iterated by fntCalcQty:
( tCalc as table, tBasis as table, tAccumulate as table ) => let nextLevel = fnCalc( tCalc, tBasis ), addTable = Table.Combine( {tAccumulate, nextLevel} ) in if Table.RowCount( nextLevel ) = 0 then tAccumulate else fntCalcQty (nextLevel, tBasis, addTable)It iterates till first empty table appears.
Final result is calculated as
let Source = fntCalcQty( tCalc1, tBOM, tCalc1), addSales = Table.Combine( {Source, tSalesRenamed} ), #"Grouped Rows" = Table.Group( addSales, {"Subpart"}, {{"TotalQty", each List.Sum([TotalQty]), type nullable number}} ), #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Subpart", Order.Ascending}}) in #"Sorted Rows"Above is in Variant 03 group in attached.
Eventually you'll have to want to find out if you're making a profit! Since you're doing that now, why not incorporate that aspect now and find out if there will be issues now.
can you imagine creating a system to calculate the quantities then later on you realize you're going to have to change it "again".
That's an interesting thought, but in this case it's a question of how much (in quantity) parts we need to order. So I really just need the desired result as stated in the workbook (and the screenshot).
The actual use case is that we have a bunch of finished products with their parts and subparts. Based on the sales quantities of the finished products, I need the quantities of the corresponding parts & subparts.
- SergeiBaklanSep 18, 2021Diamond Contributor
Detlef_Lewin , here is not exact hierarchy.
A could be part of B
B could be part of C; and could be part of D; and could be sold as separate product
A could be part of D not as part of B but directly (in addition to be in B)
etc
- Detlef_LewinSep 18, 2021Silver Contributor
I try to understand the BOM structure. So I made a BOM explosion.
I noticed that TOYCARSET1 and TOYCARSET2 are the top levels. Which is not in line with the sales table showing also TOYCAR and WHEEL.
Then I noticed that TYRE-OUTERTYRE and TYRE-INNERTYRE are on two levels.
Does that make sense?