Power Query Sum based on another column

NRS-BNE 1 Reputation point
2021-05-04T05:10:03.587+00:00

Hi,

Not sure if this question has been asked before. I have a table like below, the occurrence of ID is more than once due to the use of multiple discounts on the same order id. The amount paid is also duplicated.

ID Disc Paid
1 2 15
1 3 15
1 4 15
2 4 10
3 2 20
3 3 20

Is there an option to sum the discount and get the distinct of amount paid in the final pivot table ?

ID NO Disc Paid
1 9 15
2 4 10
3 5 20

Thanks a lot

Community Center Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lz._ 9,016 Reputation points
    2021-05-04T07:28:38.803+00:00

    Hi @NRS-BNE

    The amount paid is also duplicated => An Average should do the job then
    Group your table by [ID] and do 2 aggregations: Sum([Disc]) and Avg([Paid])

    let  
        // Table for demo:  
        Source = Table.FromColumns({  
            {1,1,1,2,3,3,3,3,4,4},  
            {2,3,4,4,2,3,4,5,1,2},  
            {15,15,15,10,20,20,20,20,17,17}},  
            type table [ID=Int64.Type, Disc=number, Paid=number]  
        ),  
        GroupedRows = Table.Group(Source, {"ID"},  
            {  
                {"NO", each List.Sum([Disc]), type nullable number},  
                {"Disc Paid", each List.Average([Paid]), type nullable number}  
            }  
        )  
    in  
        GroupedRows  
    

    93562-output.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.