August 21, 2019
Hi PQ Guru
I had tried using function to involve to get running totals for Fields1, and was wondering whether can you group by field get Index for each field 1 value, then groupby again to insert Running total in (see the following code in attachment), but get error
For all advise, please
let
Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Field 1", type text}, {"QTY", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Field 1", Order.Ascending}, {"QTY", Order.Ascending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"Field 1"}, {{"MyData", each _, type table [Field 1=nullable text, QTY=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([MyData],"Index",1,1,Int64.Type)),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MyData"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"QTY", "Index"}, {"QTY", "Index"}),
#"Grouped Rows1" = Table.Group(#"Expanded Custom", {"Field 1"}, {{"Grouped", each _, type table [Field 1=nullable text, QTY=number, Index=number]}}),
#"Added Custom1" = Table.AddColumn(#"Grouped Rows1", "Custom1", each Table.AddColumn([Grouped],"RTotal",List.Sum(List.Range(#"Grouped Rows1"[QTY],0,[Index]))))
in
#"Added Custom1"
October 5, 2010
Hi Chris,
That query is throwing an error because you don't have a Column named QTY but I think that may be beside the point.
You've only got 2 columns in your source so once you have grouped by Field 1 you haven't got any other columns to group by.
What is the result you are hoping to get? Can you please provide an example.
Regards
Phil
August 21, 2019
Hi Philip,
I am just exploring without using function method is it possible, that is the last custom column if I can insert the running total into 2nd grouping (with Index inserted in the first grouping), so I am seeking advise from you guys whether can be done, or definitely need to use function
Thank you !
October 5, 2010
Hi Chris,
I'd use a custom function to create a running total.
But that aside, your question was actually can you group by field get Index for each field 1 value, then groupby again to insert Running total.
If you've grouped Field 1 then what column are you going to group by again? An Index column will just have numbers 1,2,3 etc so can't be grouped. And with Field 1 grouped you can't insert a running total column, it'll just be a grand total for each group in Field 1.
If I am missing something then you need to supply an example of what you want as a result. The table in post #3 above does not show any groupings.
Phil
1 Guest(s)