Forum Discussion
Brite
4 years agoHelper I
Power Query - Group count
I am currently trying to group Count ZP by ID. The payment frequency above should be overwriting the one below it. This is an example of what I have right now: CountZP --> Monthly = 1, Qu...
- Anonymous4 years ago
Hi Brite ,
I think you can copy and paste my code into Advance Editor in Power Query Editor to build a virtual table by "Group By" function and then merge it with your data table.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSi4tjjc0MjZR0lEyAGI3R59gVyAdkFiZm5pXouCcn1uQk1qSqgcUMzQ2ACkxBGLf/LySjJxKMC9WhyRTjC3hpgSWJhaVpBaBzTGGm2NibGRIuWuINcXUDG6MY15eaWIOxBwjuEFGhhQFTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, amount.refunded = _t, disputed = _t, outcome.seller_message = _t, Amount = _t, count = _t, #"Payment frequecy" = _t, #"Count ZP" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"amount.refunded", Int64.Type}, {"disputed", type logical}, {"outcome.seller_message", type text}, {"Amount", Int64.Type}, {"count", Int64.Type}, {"Payment frequecy", type text}, {"Count ZP", Int64.Type}}), #"Merged Queries" = let #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Sum", each List.Sum([Count ZP]), type nullable number}}) in Table.NestedJoin(#"Changed Type", {"ID"}, #"Grouped Rows", {"ID"}, "Grouped Rows", JoinKind.LeftOuter), #"Expanded Group Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Sum"}, {"Grouped Rows.Sum"}), #"Filtered Rows" = Table.SelectRows(#"Expanded Group Rows", each ([Payment frequecy] = "Monthly")), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Count ZP"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Grouped Rows.Sum", "Count ZP"}}) in #"Renamed Columns"Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
4 years agoNot applicable
Hi Brite ,
I think you can copy and paste my code into Advance Editor in Power Query Editor to build a virtual table by "Group By" function and then merge it with your data table.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSi4tjjc0MjZR0lEyAGI3R59gVyAdkFiZm5pXouCcn1uQk1qSqgcUMzQ2ACkxBGLf/LySjJxKMC9WhyRTjC3hpgSWJhaVpBaBzTGGm2NibGRIuWuINcXUDG6MY15eaWIOxBwjuEFGhhQFTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, amount.refunded = _t, disputed = _t, outcome.seller_message = _t, Amount = _t, count = _t, #"Payment frequecy" = _t, #"Count ZP" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"amount.refunded", Int64.Type}, {"disputed", type logical}, {"outcome.seller_message", type text}, {"Amount", Int64.Type}, {"count", Int64.Type}, {"Payment frequecy", type text}, {"Count ZP", Int64.Type}}),
#"Merged Queries" =
let #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Sum", each List.Sum([Count ZP]), type nullable number}}) in
Table.NestedJoin(#"Changed Type", {"ID"}, #"Grouped Rows", {"ID"}, "Grouped Rows", JoinKind.LeftOuter),
#"Expanded Group Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Sum"}, {"Grouped Rows.Sum"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Group Rows", each ([Payment frequecy] = "Monthly")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Count ZP"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Grouped Rows.Sum", "Count ZP"}})
in
#"Renamed Columns"
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.