Select from table1 where not in select from table2

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,895
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
  8. 2003 or older
Platform
  1. Windows
for example I have a table1 which contains member names and other information , I also have a table2 which contains a list of names and a column called IsCurrent which is a simple Y/N
I am trying to identify new members in table1 that are not in table2 where IsCURRENT=“Y”
In rough sql it might be

Select name from table1 where name not in (select name from table2 where iscurrent=“Y”)

I can then check these new names have paid their membership and add to table2
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Source tables: Table1 and Table2
Book1
ABCDE
1Member NameOther InfoMember NameIsCurrent
2a123aY
3b234cY
4c456dN
5d567
6e678
Sheet1

Assuming the "Member Name" column contains unique values in Table2 (or you'll probably use an ID column instead).

M Code goes to PQ->New Blank Query->Advanced Editor:
Power Query:
let
    Table1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Table2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    FilterTable2 = Table.SelectRows(Table2, each [IsCurrent] <> "Y"),
    Join = Table.Join(Table1, {"Member Name"}, FilterTable2, {"Member Name"}),
    Result = Table.RemoveColumns(Join,{"IsCurrent"})
in
    Result

Make sure using the corresponding table and columns names, then you get the matched rows.
Book1
AB
1Member NameOther Info
2d567
Result
 
Upvote 0
Many thanks for that I will try it later
I was thinking along those lines but I wasn’t sure if a join operation would be applied to the raw table or the last known state ie filtered in this case, so I didn’t know how to apply the iscurrent=“y”
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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