Forum Discussion
Rich_P
6 years agoHelper II
FillDown with a Calculation
I'm not quite sure the Subject is descriptive enough, so I'll try to explain with images. I have a data feed that displays Subtotals on the first record of a group of records and I need to display t...
- Anonymous6 years ago
This code will handle the task in one query. It shows how you can join from one step into another.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"MaterialCode", type text}, {"ProdSequence", type text}, {"Operation", type text}, {"Material", type any}, {"Qty", type number}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1), #"Added Custom" = Table.AddColumn(#"Added Index", "Header", each if [Qty] = null then null else [Index]), #"Filled Down" = Table.FillDown(#"Added Custom",{"Header"}), #"Grouped Rows" = Table.Group(#"Filled Down", {"Header"}, {{"Count", each Table.RowCount(_), type number}}), #"Merged Queries" = Table.NestedJoin(#"Filled Down",{"Header"},#"Grouped Rows",{"Header"},"Grouped Rows",JoinKind.LeftOuter), AddQtyAdjust = Table.AddColumn(#"Merged Queries", "QtyAdjust", each [Qty]/[Grouped Rows][Count]{0}), #"Filled Down1" = Table.FillDown(AddQtyAdjust,{"Material", "QtyAdjust"}), #"Removed Other Columns" = Table.SelectColumns(#"Filled Down1",{"MaterialCode", "ProdSequence", "Operation", "Material", "QtyAdjust"}) in #"Removed Other Columns"
Anonymous
6 years agoNot applicable
This code will handle the task in one query. It shows how you can join from one step into another.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"MaterialCode", type text}, {"ProdSequence", type text}, {"Operation", type text}, {"Material", type any}, {"Qty", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Header", each if [Qty] = null then null else [Index]),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Header"}),
#"Grouped Rows" = Table.Group(#"Filled Down", {"Header"}, {{"Count", each Table.RowCount(_), type number}}),
#"Merged Queries" = Table.NestedJoin(#"Filled Down",{"Header"},#"Grouped Rows",{"Header"},"Grouped Rows",JoinKind.LeftOuter),
AddQtyAdjust = Table.AddColumn(#"Merged Queries", "QtyAdjust", each [Qty]/[Grouped Rows][Count]{0}),
#"Filled Down1" = Table.FillDown(AddQtyAdjust,{"Material", "QtyAdjust"}),
#"Removed Other Columns" = Table.SelectColumns(#"Filled Down1",{"MaterialCode", "ProdSequence", "Operation", "Material", "QtyAdjust"})
in
#"Removed Other Columns"
- Rich_P6 years agoHelper II
MC -
This is exaclty what I was hoping for. Such a simple, elegant solution. And a great example of how to leverage results from previous steps.
Thanks for taking the time to do this.
Happy Holidays!
RichP