Forum Discussion
Need help with list.Sum custom colomns
- 5 years ago
Hello Timo1980
add a new column and enter this formula. The only thing you have to pay attention is that the variable ChangedType you have to replace with your prior step name.
List.Sum(Table.SelectRows(ChangedType, (sel)=> sel[Customer]=[Customer] and sel[Revenue]>=0)[Revenue])here the complete code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYQOlWB0I1wjEtQBznaBcI1Mw1xnGNYZzdUF8XYi0C4gJMkzXAs4HSVui8AyBimMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, QTY = _t, Revenue = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"QTY", Int64.Type}, {"Revenue", Int64.Type}}), #"Added Custom" = Table.AddColumn(ChangedType, "Total Revenue", each List.Sum(Table.SelectRows(ChangedType, (sel)=> sel[Customer]=[Customer] and sel[Revenue]>=0)[Revenue])), #"Added Custom1" = Table.AddColumn(#"Added Custom", "%", each [Revenue]/[Total Revenue],Percentage.Type) in #"Added Custom1"and here is the output
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hello Timo1980
add a new column and enter this formula. The only thing you have to pay attention is that the variable ChangedType you have to replace with your prior step name.
List.Sum(Table.SelectRows(ChangedType, (sel)=> sel[Customer]=[Customer] and sel[Revenue]>=0)[Revenue])
here the complete code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYQOlWB0I1wjEtQBznaBcI1Mw1xnGNYZzdUF8XYi0C4gJMkzXAs4HSVui8AyBimMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, QTY = _t, Revenue = _t]),
ChangedType = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"QTY", Int64.Type}, {"Revenue", Int64.Type}}),
#"Added Custom" = Table.AddColumn(ChangedType, "Total Revenue", each List.Sum(Table.SelectRows(ChangedType, (sel)=> sel[Customer]=[Customer] and sel[Revenue]>=0)[Revenue])),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "%", each [Revenue]/[Total Revenue],Percentage.Type)
in
#"Added Custom1"
and here is the output
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy