Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
3 years ago
Solved

Removing Duplicates from Merged Tables in Power Query

I am doing a reconciliation from two different data set to find variances but when I do a full outer join between the tables I get duplicates if one of the tables are more than one row for the merge fields. There no unique identifier so I'm merging them using Resource, Date and hours

 

Table A   
ResourceInvoice IDDateHours
John Doe123458/28/202340
Table B   
ResourceInvoice IDDateHours
John Doe456788/28/202340
John Doe987658/28/2023-40
John Doe765438/28/202340

 

Here's what I'm getting: 

Table A Resource

Table A

Invoice ID

Table A DateTable A Hours

Table B

Resource

Table B Invoice IDTable B DateTable B Hours
John Doe123458/28/202340John Doe456788/28/202340
John Doe123458/28/202340John Doe987658/28/2023-40
John Doe123458/28/202340John Doe765438/28/202340

 

Here's what I want to see:

Table A ResourceTable A Invoice IDTable A DateTable A HoursTable B ResourceTable B Invoice IDTable B DateTable B Hours
John Doe123458/28/202340John Doe456788/28/202340
   40John Doe987658/28/2023-40
   40John Doe765438/28/202340

 

Can someone help me, please?

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Syndicate_Admin ,

     

    Please try:

    1. Add an index column to both tables;

    2.  Merge Queries --> Merge Queries as New --> Select Table A as the first table and Table B as the second table --> Select the Resource, Date, Hours, and Index columns in both tables --> Choose the Full Outer join type and click OK

    3. Expand the new merged column to include the desired columns from Table B.

    4. Rename the columns as needed.

     

    Result:

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

4 Replies

  • Martin_D's avatar
    Martin_D
    Solution Sage

    You cannot produce the result you want from a single merge step. If your requirements demand these empty cells then you need to clean up them afterwards. E.g., you could compare the first 3 columns with the previous row as described here, check whether a Table A row is a duplicate of the previous row, and add custom columns in your first-and-blank-rows format. Then finally remove the columns from table A from the merge result that you don't want to have.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Syndicate_Admin ,

     

    Please try:

    1. Add an index column to both tables;

    2.  Merge Queries --> Merge Queries as New --> Select Table A as the first table and Table B as the second table --> Select the Resource, Date, Hours, and Index columns in both tables --> Choose the Full Outer join type and click OK

    3. Expand the new merged column to include the desired columns from Table B.

    4. Rename the columns as needed.

     

    Result:

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

  • If a data is only in Table B, I would want the merged record in Table A to show null. How can I compare a null value to previous row only for data that are in both tables?

  • This only works for the first record. If there's a same information for another resource, then I'm getting all records from Table A and Table B without any match. For example: If my table are:

    Table A    
    ResourceInvoice IDDateHoursIndex
    John Doe123458/28/2023400
    John Doe2222210/10/2023321

     

     

    Table B    
    ResourceInvoice IDDateHoursIndex
    John Doe456788/28/2023400
    John Doe987658/28/2023-401
    John Doe765438/28/2023402
    John Doe3333310/10/2023323
    John Doe4444410/10/2023-324
    John Doe5555510/10/2023325

     

    I'm getting:

    ResourceTableA.Invoice IDTableA.DateTableA.HoursTableB.Invoice IDTableB.DateTableB.Hours
    John Doe123458/28/202340456788/28/202340
    nullnullnullnull987658/28/2023-40
    nullnullnullnull765438/28/202340
    nullnullnullnull3333310/10/202332
    nullnullnullnull4444410/10/2023-32
    nullnullnullnull5555510/10/202332
    John Doe2222210/10/202332nullnullnull

     

    What I want to get is:

    ResourceTableA.Invoice IDTableA.DateTableA.HoursTableB.Invoice IDTableB.DateTableB.Hours
    John Doe123458/28/202340456788/28/202340
    nullnullnullnull987658/28/2023-40
    nullnullnullnull765438/28/202340
    John Doe2222210/10/2023323333310/10/202332
    nullnullnullnull4444410/10/2023-32
    nullnullnullnull5555510/10/202332