Comparing two columns in the same table, and returning unmatched.

Richard U

Active Member
Joined
Feb 14, 2006
Messages
406
Office Version
  1. 365
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
I'm looking to find all the rows where column B does NOT match column A

COLACOLBData1Data2
USNTSUSNTSABC
123​
USNTSUSSPZABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USMSYUSMSYABC
123​
USHOUUSHOUABC
123​
USMSYUSMSYABC
123​
USMSYUSMSYABC
123​
USLVVUSNYCABC
123​
USNYCUSNYCABC
123​

So, The output should look like this

USNTSUSSPZABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USNTSUSLVVABC
123​
USMSYUSMSYABC
123​
USLVVUSNYCABC
123​

I've been hacking around on this all day. This is my third day using power BI, and I could use a little help (Yes, I'm out of my depth)
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
With Power Query
1. Load your table to the PQ editor (found on the Data Tab as Get and Transform Data)
2. Remove column B from the table.
3. Copy the table and delete the steps so that it looks like the original
4. Remove column A from the table.
5 Join the two tables you now have with a Right Anti join.

Result:
Book7
ABC
1Table2.COLBTable2.Data1Table2.Data2
2USSPZABC123
Merge1


Mcode for first table

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"COLA", type text}, {"COLB", type text}, {"Data1", type text}, {"Data2", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"COLB"})
in
    #"Removed Columns"

Mcode for the second table
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"COLA", type text}, {"COLB", type text}, {"Data1", type text}, {"Data2", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"COLA"})
in
    #"Removed Columns"

Code for the Anti Join

Power Query:
let
    Source = Table.NestedJoin(Table1, {"COLA"}, Table2, {"COLB"}, "Table2", JoinKind.RightAnti),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"COLB", "Data1", "Data2"}, {"Table2.COLB", "Table2.Data1", "Table2.Data2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"COLA", "Data1", "Data2"})
in
    #"Removed Columns"
 
Upvote 0
Solution

Forum statistics

Threads
1,222,287
Messages
6,165,101
Members
451,933
Latest member
EP25

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top