Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Merge two tables and avoid duplicates

Hello,

I have the following two tables and i am trying to create a new table in Power Query - merge and keep only the rows in the Reference table which are not found in the Exceptions table. Please note that there are duplicate names in the Exceptions table. Is it possible to do this all in Power Query? Any help is much appreciated!

 

Reference table:

Student Name
Lizui
Laufenburg
Tegalpapak
Ar Rabiyah
Bellegarde
Gangarampur
Luntas
Frei Paulo
Seedorf
Cosamaloapan de Carpio
Zagrodno

 

Exceptions table:

Student nameReason
Zagrodnosick
Luntassick
Gangarampursick
Luntassick
Frei Pauloblank
Gangarampurblank
Luntasblank
Frei Paulolate
Zagrodnoblank
Seedorfblank
Gangarampurlate
1 ACCEPTED SOLUTION
Anonymous
Not applicable

let
    Source = Table.NestedJoin(reftab, {"Student Name"}, exctab, {"Student name"}, "exctab", JoinKind.LeftOuter),
    #"Lowercased Text" = Table.TransformColumns(Source,{{"exctab", each Text.Combine([Reason],", "), type text}})
in
    #"Lowercased Text"

buoni e cattivi.png

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

exclusion.png

ImkeF
Super User
Super User

Hi @Anonymous ,
you can expand the "Reason"-column from the merged table.
But you have to decide how to deal with multiple different entries for one student: Do you only want to keep the first/last or even concatenate them?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Super User
Super User

Hi @Anonymous ,

when merging tables, you can adjust the join type to keep only those rows which are NOT included in the other table. That's called a "Left Anti Join": Multiple JOINS Types for Beginners | Power Query and Power BI (2021) Tutorial - YouTube

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

@ImkeF I got this result and it looks correct:

MakeItReal_0-1650229764552.png

But i have two questions:

1. Is it safe to delete the new column to the right or is it important to keep it?

2. Is it possible to bring in the "Reason" column from the Exceptions table into the result table?

Anonymous
Not applicable

let
    Source = Table.NestedJoin(reftab, {"Student Name"}, exctab, {"Student name"}, "exctab", JoinKind.LeftOuter),
    #"Lowercased Text" = Table.TransformColumns(Source,{{"exctab", each Text.Combine([Reason],", "), type text}})
in
    #"Lowercased Text"

buoni e cattivi.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors