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.
Based on current dataset, the number of Children per parent does not look correct?
Comp3 has 100 children and
Comp3.1 has 20 children?
So Comp3 has 100 x 20 x Comp3.1.1.
The quantities only refer to 1 level lower.
- Yea_SoSep 15, 2021Bronze Contributor
So you're saying Comp3 has 100 children, its just not showing in the current sample dataset.
- bartvanaSep 15, 2021Iron Contributor
No, not really. Comp3 has 100 children (named Comp3.1), and each of these children has 20 children (Comp3.1.1), which are grandchildren if Comp3.1. So Comp3 has 100 children Comp3.1, and 2000 grandchildren Comp3.1.1.
(Apart from that branch, there are also other children and grandchildren, like Comp3.2 and Comp3.2.1.)I did make an error, I see now, with Comp3.2 and Comp3.1.2, I'll fix that when I get home. But maybe you can see the general idea?Update: the data as such was correct, but it's more logical to name 3.1.2 3.2.1, so I attached a new workbook.