Forum Discussion

LP280388's avatar
LP280388
Resolver II
3 years ago
Solved

Power Query - Sum all columns values expect one

Hi Team, I'm trying to add the numbers in all columns except one text column.  the columns will increase/decrease based on data population from different DB environments.  So, im trying to capture t...
  • LP280388's avatar
    3 years ago

    I found the answer https://youtu.be/X2AcnH0F6CA?t=4630 and tweaked to my need. Posting it so that others can use it. 

    = Table.AddColumn(#"Pivoted Column", "Addition", each List.Sum(Record.FieldValues(Record.SelectFields(_,List.RemoveMatchingItems(Table.ColumnNames(#"Pivoted Column"),{"empid"})))), type number)

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi LP280388 ,

    You can also get it by the following codes, please find the details in the attachment.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqqisMlTSUTICYmMgBrENlGJ1wBIgQROopBFYEiphDBUwgOuESpig6TCBSZhCVZtCMVAiFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [empid = _t, assigned = _t, completed = _t, satisfied = _t, inprogress = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"empid", type text}, {"assigned", Int64.Type}, {"completed", Int64.Type}, {"satisfied", Int64.Type}, {"inprogress", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Total column",  each List.Sum(List.Range(Record.ToList(_),1,Table.ColumnCount(Source)-1)))
    in
        #"Added Custom"

     

    And it's glad to hear that your problem has been resolved. Thanks for sharing your solution here. Could you please mark your post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours.  Thank you.

    Best Regards