Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Sum of Value filtering Unique Rows

I have a column that I had to split which equated to more rows. I currently use the Distinct Count from the ID row for most count based visuals.

 

I need to get the sum of certain columns but I dont want it to add every row.

 

IDMaterial Used
1100
1100
1100
2380
3421
3421
4100

 

This should only equal 1001. As you can see, the sum of unique values in the materials column wouldnt work since values may match. The ID column needs to be referenced as the control column.

1 Reply

  • Jimmy801's avatar
    Jimmy801
    Community Champion

    Hello Anonymous 

     

    I don't know how you want to show it. In my code i take your table, and make a sum of a distincted table and show only the result of that

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0MFCK1cHNNgKyjS0gbGMg28TIEINtAlMfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Material Used" = _t]),
        ChangeType = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Material Used", Int64.Type}}),
        Sum = List.Sum(Table.Distinct(ChangeType)[Material Used])
    in
        Sum

     

    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