Search code examples
excelpowerquerym

Join two tables with OR logic in PowerQuery


As the title states, I am trying to do a merge of 2 tables. I want a nested joint where the values from the first table are always there and rows matching the second table are added to the first. I believe this is known as the nested join.

Unfortunately, it only allows for 1 key to 1 key matching where as I need it for 1 key in table 1 to 2 keys in table 2

Here is an example

Table1:

Group
..
..
Time
Date


Table2:

Group 1
Group 2
..
..
..
Other Info

What I want is where "Group = Group 1 OR Group = Group 2" and display the matching row from table 2 nested into Table 1

I looked at the following example but I must be confused by the syntax because it doesn't seem to be working for me.

How to join two tables in PowerQuery with one of many columns matching?


Solution

  • So after further investigation of the answer post I linked earlier, I will add an explanation of it here:

    Table.AddColumn(Source, "Name_of_Column",
        (Q1) => Table.SelectRows(Query2,
                    each Q1[Col_from_q1] = [Col_from_q2] or Q1[Col_from_q1] = [2_Col_from_q2]
                )
    )
    

    So this did work for me and it adds an extra column that needs to be expanded to get all the values from the table. What i would add is that I don't know / haven't tested if there are multiple matches and how it treats it, based on nestedjoin, I would assume that it will duplicate rows in the first table.