Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

remove duplicates based on values in 2 columns

Hello there,  I've got 2 tables: table 1 contains sales data based on a key which is product-volume combination. sales are captured on this key table 2 is my item master table, I can have several ...
  • Ritaf1983's avatar
    3 years ago

    Hi Anonymous 
    I am not sure that I understood your goal completely,
    It sounds like you need a group by your data, with aggregation by maximum code, if it is on separate columns you can concatenate them before the grouping.
    Tutorial to concatenating columns:
    https://excelchamps.com/power-query/concatenate/

    Group by here:
    https://learn.microsoft.com/en-us/power-query/group-by

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

  • Ahmedx's avatar
    3 years ago

    pls try this

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxK1jXQM1fSUTI0MDAEUXpGpkqxOqgyRgY4ZIzMTOAysQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"product-size" = _t, #"item code" = _t, price = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"product-size", type text}, {"item code", Int64.Type}, {"price", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"product-size"}, {{"Count", (x)=>Table.SelectRows(x, each [item code]=List.Max(x[item code]))}}),
        #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"Count"}),
        #"Expanded Count" = Table.ExpandTableColumn(#"Removed Other Columns", "Count", {"product-size", "item code", "price"}, {"product-size", "item code", "price"})
    in
        #"Expanded Count"