Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Remove duplicates based on Multiple Columns

Hi there,   I have a table with 3 columns in it. Staff, Staff Position, Client. Some staff members can have multiple positions with the same client. Some clients can have multiple staff members as...
  • v-jingzhang's avatar
    4 years ago

    Hi Anonymous 

     

    You could try this method

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspPUtJR8k3MS0xPLQKy3PPz03NSlWJ1YFIBiUUleehSzhlFmcUo+hxzE6vy88CSjjmpFShyPvnlqcVgqaDKxDwUM6FSsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Staff = _t, #"Staff Position" = _t, Client = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Staff", type text}, {"Staff Position", type text}, {"Client", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Staff", "Client"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"AllData", each _, type table [Staff=nullable text, Staff Position=nullable text, Client=nullable text]}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each if [Count] > 1 then Table.SelectRows([AllData], each [Staff Position] <> "Manager") else [AllData]),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Staff", "Staff Position", "Client"}, {"Staff", "Staff Position", "Client"})
    in
        #"Expanded Custom"

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.