Forum Discussion

Timo1980's avatar
Timo1980
Advocate I
5 years ago
Solved

Need help with list.Sum custom colomns

Hi All,   i have the following issue in Power Query i want to create a customer colomn ( i know i can do this with grouping or in Dax, but i need to to this in power query) Table 1 is the data and ...
  • Jimmy801's avatar
    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