Forum Discussion
Relationship between two tables with repeated values
Hi guys, I have two tables that I need to establish a relation but I`m having some trouble. If anyone could help me I would be very grateful.
01. The first one called "Disparo" with the columns "Lote", "Date" and "Email", where each day I have a new "Lote" number and the same email range, like this:
| Lote | Date | |
| 98DJSH4723HM | May 15 | [email protected] |
| 98DJSH4723HM | May 15 | [email protected] |
| 98DJSH4723HM | May 15 | [email protected] |
| 53KJS38R7FNK3 | May 16 | [email protected] |
| 53KJS38R7FNK3 | May 16 | [email protected] |
| 53KJS38R7FNK3 | May 16 | [email protected] |
02. The second one its called "Respostas" and has the columns "ID", "Lote", "Email" and "Nota", where each new "Lote" I have the same group of "Email" but with different "ID" and "Nota" that can be 1 or 2, like this:
| ID | Lote | Nota | |
| 26785519 | 98DJSH4723HM | [email protected] | 2 |
| 25485223 | 98DJSH4723HM | [email protected] | 2 |
| 13984709 | 98DJSH4723HM | [email protected] | 1 |
| 32955799 | 53KJS38R7FNK3 | [email protected] | 2 |
| 38964801 | 53KJS38R7FNK3 | [email protected] | 1 |
| 45997758 | 53KJS38R7FNK3 | [email protected] | 2 |
Now what I need to do is to "pass" the column "ID" from Table 02 to Table 01 so I can create a relation between them and get the "Nota" column according to "Email" and "Lote" (because ID is the only column with unique values since "Lote" and "Email" repeats). I can't do a LOOKUPVALUE with "Email" because I have the same emails in every "Lote".
Any suggestions? Thank you very much.
3 Replies
- ChrisMendoza
Resident Rockstar
Anonymous -
Are you opposed to merging both tables with a join in Power Query? Edit - this does essentially the same thing as a compound key
let Source = Table.NestedJoin(TableOne, {"Lote", "Email"}, TableTwo, {"Lote", "Email"}, "TableTwo", JoinKind.LeftOuter), #"Expanded TableTwo" = Table.ExpandTableColumn(Source, "TableTwo", {"ID", "Nota"}, {"TableTwo.ID", "TableTwo.Nota"}) in #"Expanded TableTwo"The other option I can think of is creating a compound key with your existing columns.
- AnonymousNot applicable
Hi ChrisMendoza thank you very much for your answer. I tried to do the join but it isn't working for all the lines I have and most of them are receving "null". Do you know what can be?
- ChrisMendoza
Resident Rockstar
Anonymous -
It means that a match was not found. Refer to https://www.powerbi-pro.com/en/power-bi-seven-types-of-table-joins/ for a graphical representation of what is occurring.
Possibly you require an inner join?