Forum Discussion

Quiny_Harl's avatar
Quiny_Harl
Advocate III
2 years ago
Solved

How to identify duplicate column records in Power Query

Hello,

Is there a straightforward way to identify/flag duplicate column records in Power Query?
When I say straightforward, I mean something that doesn't involve aggregations like this method for example, because I don't want to aggregate my table or add too many steps.
I'm looking for the Power Query equivalent of this DAX code.

  • Hi Quiny_Harl, don't be affraid of using Group By - it is one of my favourite functions.

     

    You can achieve what you need in single step.

     

    This code will preserve all your exicting columns and add new [Duplicate Flag] at the end.

    Add this code as new step, but replace Source with your previous step reference and "PK" with your column name where you want to check for duplicates

     

    Table.Combine(Table.Group(Source, {"PK"}, {{"All", each
            Table.AddColumn(_, "Duplicate Flag", (x)=> Table.RowCount(_), Int64.Type), type table}})[All])

     

     

12 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Not so, you can right-click on a single column or multiple columns, and select "Remove duplicates".  It will remove duplicates in the field(s) you selected, regardless of what else is in the row.

     

    --Nate

  • dufoq3's avatar
    dufoq3
    Community Champion

    Hi Quiny_Harl, don't be affraid of using Group By - it is one of my favourite functions.

     

    You can achieve what you need in single step.

     

    This code will preserve all your exicting columns and add new [Duplicate Flag] at the end.

    Add this code as new step, but replace Source with your previous step reference and "PK" with your column name where you want to check for duplicates

     

    Table.Combine(Table.Group(Source, {"PK"}, {{"All", each
            Table.AddColumn(_, "Duplicate Flag", (x)=> Table.RowCount(_), Int64.Type), type table}})[All])

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    No way to do it without aggregating, if you are trying to keep the duplicates and mark them somehow. Just group, add a count column, add the All Rows column, then expand the table column. All of your counts above 1 are duplicates.

     

    Not sure what else you might have envisioned.

     

    --Nate

  • please define "duplicate"  and "identify".  Does that include the first occurrence? If yes then you can do a table self join.