Forum Discussion
JOINING TABLES WITH MULTIPLE VALUES (Many to Many relationship)
Hello,
I am trying to Join two tables that do not have unique identifiyers but I am getting many errors. These are the tables:
Table 1:
| Son Code | Parent code |
| Code 1 | Code A |
| Code 2 | Code B |
| Code 2 | Code C |
| Code 3 | Code D |
Table 2:
| Son Code | Sale amount |
| Code 1 | 45 |
| Code 2 | 35 |
| Code 2 | 15 |
| Code 1 | 46 |
| Code 3 | 48 |
As you can see, If i connect both tables, by "Son Code" I will get a many to many relationship. What i am willing to get is a third table having the "Code 2" rows duplicated in order to identify all the "Parent Code"s I have in the table 1 for each "Code Son" in the table 2.
This should be the result (In red the new rows):
Table3:
| Son Code | Sale amount | Parent Code |
| Code 1 | 45 | Code A |
| Code 2 | 35 | Code B |
| Code 2 | 35 | Code C |
| Code 2 | 15 | Code B |
| Code 2 | 15 | Code C |
| Code 1 | 46 | Code A |
| Code 3 | 48 | Code D |
In MS Acess I was able to get it by doing a simple LEFT JOIN.
Thank you
Hi jauzmendi
Please refer to attached sample file with the proposed solutionTable3 = GENERATE ( Table1, SELECTCOLUMNS ( FILTER ( Table2, Table2[Son Code] = Table1[Son Code] ), "Sales Amont", [Sale amount] ) )
3 Replies
- jauzmendiFrequent Visitor
First of all thanks for response! The idea is very very good!
Although it is helpfull,I actually need to do i the other way. Instead of replicating Table 1 and include the Sales amount, I need to Replicate Table 2 and include Parent Code.
I can use your idea and include one by one all the columns from Table 2 but it's not the best idea I think .Thanks