Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Find missing records between two tables

Hello all,

 

I have two different data sources in two different databases / languages.

What I want to do is use Powerbi to automate & find which records  are missing from database 2.

Database 1 will always contain all the records but database 2 will be missing records.

 

I have a attached a Pbix example here

 

the data looks like this:

 

database 1 - table: customers database 2 - table: clientcustomers
CustomerCustomerID CustomerCustomerID
Walmart1 Walmart1
Winco2 Winco2
Target3 Target3
Amazon4 Amazon4
Costco5 Costco5
Frenchs6   
Roses7   
Cash & Carry8   
Yokes9   
     

 

and my desired output would show:

 

Preferred Output (missing records from database 2)
CustomerCustomerID
Frenchs6
Roses7
Cash & Carry8
Yokes9

 

 

How can I accomplish this in Powerbi?

 

thank you!

  • Do an ANTI-JOIN in Power Query.

    1. Select the first table. You can create a reference to that table if you don't want to distrupt that table first.
    2. Select the Merge button on the Home Ribbon
    3. Configure the dialog box as below. My Database 1 Customers (2) is because I created a reference.

    It returns this:

     

    If you want to see the M code doing this, create a blank query and put this code in:

    1) In Power Query, select New Source, then Blank Query
    2) On the Home ribbon, select "Advanced Editor" button
    3) Remove everything you see, then paste the M code I've given you in that box.
    4) Press Done

    let
        Source = #"Database 1 - Customers",
        #"Merged Queries" = Table.NestedJoin(Source, {"CustomerID"}, #"database 2 - clientcustomers", {"CustomerID"}, "database 2 - clientcustomers", JoinKind.LeftAnti),
        #"Removed Columns" = Table.RemoveColumns(#"Merged Queries",{"database 2 - clientcustomers"})
    in
        #"Removed Columns"

2 Replies

  • edhans's avatar
    edhans
    Community Champion

    Do an ANTI-JOIN in Power Query.

    1. Select the first table. You can create a reference to that table if you don't want to distrupt that table first.
    2. Select the Merge button on the Home Ribbon
    3. Configure the dialog box as below. My Database 1 Customers (2) is because I created a reference.

    It returns this:

     

    If you want to see the M code doing this, create a blank query and put this code in:

    1) In Power Query, select New Source, then Blank Query
    2) On the Home ribbon, select "Advanced Editor" button
    3) Remove everything you see, then paste the M code I've given you in that box.
    4) Press Done

    let
        Source = #"Database 1 - Customers",
        #"Merged Queries" = Table.NestedJoin(Source, {"CustomerID"}, #"database 2 - clientcustomers", {"CustomerID"}, "database 2 - clientcustomers", JoinKind.LeftAnti),
        #"Removed Columns" = Table.RemoveColumns(#"Merged Queries",{"database 2 - clientcustomers"})
    in
        #"Removed Columns"
    • Anonymous's avatar
      Anonymous
      Not applicable

      thank you for the quick response!!!! I will try later tonight and follow up if I have anymore questions.