Forum Discussion
Combining duplicate rows, sum some values and keep others
- 1 year ago
you can try this
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY/LCsMgEEV/RVy34luzbFLBFNGi6aKE/P9vVBMthlIQ5t6Rw2HWFXKiGLxAxgWXeT6MB2N8zT7lMi/lhyBcfvA3b5cVCixpXlBBlchzNM4ZMIWbyyW/K5MIk0rV0mHNdsJ2m5Bo4JU7csGUHPTJ5sEUjbk3ijNEK7THwjDNh06VbHa9QQxjCr5xVCPdwCMXUlI5dLbJxjkt4WlNBM6YvLGxXMUJoqqdeJSObt5f+t+d2wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"ID Number" = _t, #"Account Number" = _t, Name = _t, Department = _t, #"Current Charges" = _t, #"Total Adjustments" = _t, #"Total Charges And Adjustments" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID Number", Int64.Type}, {"Account Number", Int64.Type}, {"Name", type text}, {"Department", type text}, {"Current Charges", type number}, {"Total Adjustments", Int64.Type}, {"Total Charges And Adjustments", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "New Account Number", each Table.Sort( Table.SelectRows(#"Added Index",(x)=>[ID Number]=x[ID Number]),{{"Index", Order.Descending}}){0}[Account Number]),
Custom1 = Table.AddColumn(#"Added Custom", "New department", each Table.Sort( Table.SelectRows(#"Added Index",(x)=>[ID Number]=x[ID Number]),{{"Index", Order.Descending}}){0}[Department]),
#"Grouped Rows" = Table.Group(Custom1, {"ID Number", "New Account Number", "New department"}, {{"charges", each List.Sum([Current Charges]), type nullable number}, {"adjustment", each List.Sum([Total Adjustments]), type nullable number}, {"total", each List.Sum([Total Charges And Adjustments]), type nullable number}})
in
#"Grouped Rows"pls see the attachment below
Hi LauraB ,
We wanted to kindly follow up regarding your query. If you need any further assistance, please reach out.
Thank you.