Forum

Merge Two tables - ...
 
Notifications
Clear all

Merge Two tables - match Table_1 with either col_1, or col_2, or col_3, or col_4 from Table_2

9 Posts
2 Users
0 Reactions
103 Views
(@robbieg)
Posts: 39
Trusted Member
Topic starter
 

Hello again,

I have a connection to a sheet with 5 million rows in the table and want to filter the rows with a value that is in column_1 or in column_2 or in column_3 or in column_4.

So I'm using PQ with a second table containing the search terms and trying to merge the tables.

There might be 100k results from column_1, 50k from column_2, 25k from column_3 and 10k from column_4. I would like a single result with all 185k rows.

I can do this for one column, but struggling to do it on multiple columns. Can you advise please?

Thanks 

 
Posted : 20/05/2022 3:59 am
Riny van Eekelen
(@riny)
Posts: 1219
Member Moderator
 

Perhaps you can upload a small data set demonstrating what you have in mind. Raw data as you would find it in the 5 million row table, the table with the search terms and the desired end result.

 
Posted : 20/05/2022 4:53 am
(@robbieg)
Posts: 39
Trusted Member
Topic starter
 

I've attached a file with an example source table (the original has 5m rows), a table with >1 search terms, and a table what the results would look like.

I can perform 4 merges in PQ to get a results for each column merge and then append the results, but I am wondering if it is possible to perform the search in one merge or similar?

Note that Ethan and Oliver appear in both searches but result in only one 'find'

Thanks

 
Posted : 20/05/2022 12:55 pm
Riny van Eekelen
(@riny)
Posts: 1219
Member Moderator
 

Thanks, but I don't see a file. Did you press the "Upload" button?

 
Posted : 20/05/2022 2:18 pm
(@robbieg)
Posts: 39
Trusted Member
Topic starter
 

Hmm. Obviously not 🙂

 
Posted : 21/05/2022 4:51 am
Riny van Eekelen
(@riny)
Posts: 1219
Member Moderator
 

The attached file contains two possible solutions. One that begins with a traditional UNPIVOT step, then one merge with the Search table. Filter out the nulls, remove duplicates and merge again with the original source.

An alternative solution seem much neater. It converts the source to one column with lists that are then checked against the items in the Search table. Filter and convert a single column of lists back to a regular table.

Both work, but I can't really oversee which how either of them will perform in i.r.l. on a table with 5 million rows.

 
Posted : 21/05/2022 6:20 am
(@robbieg)
Posts: 39
Trusted Member
Topic starter
 

Thank you Riny. Very interesting results. I need to get a DAX course!!

I wil have a go with the large file and see how they respond.

Warm regards

 
Posted : 22/05/2022 6:01 am
Riny van Eekelen
(@riny)
Posts: 1219
Member Moderator
 

Hi Robert,

Glad I could help! And, by the way, DAX relates to Power Pivot / Data Model. You'll need to dive into M, the code language that drives Power Query, in order to follow some of the techniques used here.

Power Query M formula language reference - PowerQuery M | Microsoft Docs

Curious to hear how it goes with real data on a much larger scale.

 
Posted : 22/05/2022 7:02 am
(@robbieg)
Posts: 39
Trusted Member
Topic starter
 

Of course! 

 
Posted : 25/05/2022 10:50 am
Share: