Forum Discussion
Join 2 tables into a third using a factor
Hello,
I'm trying to get the following result:
Table A
| DATE | ID | Product |
| 1/1/2021 | A | 123 |
| 2/1/2021 | A | 121 |
| 3/1/2021 | A | 128 |
| 1/1/2021 | B | 243 |
| 2/1/2021 | B | 233 |
| 3/1/2021 | B | 242 |
| 1/1/2021 | C | 565 |
| 2/1/2021 | C | 566 |
| 3/1/2021 | C | 556 |
Table B
| DATE | ID2 | Product2 |
| 1/1/2021 | J | 5 |
| 2/1/2021 | J | 6 |
| 3/1/2021 | J | 5 |
| 1/1/2021 | Q | 3 |
| 2/1/2021 | Q | 2 |
| 3/1/2021 | Q | 3 |
| 1/1/2021 | M | 1 |
| 2/1/2021 | M | 1 |
| 3/1/2021 | M | 1.1 |
Table C
| ID1 | ID2 | f |
| A | J | 0.5 |
| A | Q | 0.3 |
| B | J | 0.5 |
| B | Q | 0.3 |
| B | M | 0.5 |
| C | M | 0.5 |
I want to Join Table A and B by using the relationship in table C.
For each Product of table A you have some asociated products of table B and the production is multiplied by a factor
So the output would be something like:
| DATE | ID | Product | Asoc. Prod |
| 1/1/2021 | A | 123 | 3.4 |
| 2/1/2021 | A | 121 | 3.6 |
| 3/1/2021 | A | 128 | 3.4 |
| 1/1/2021 | B | 243 | 3.9 |
| 2/1/2021 | B | 233 | 4.1 |
| 3/1/2021 | B | 242 | 3.95 |
| 1/1/2021 | C | 565 | 0.5 |
| 2/1/2021 | C | 566 | 0.5 |
| 3/1/2021 | C | 556 | 0.55 |
The first row would be: (5 * 0.5 + 3 * 0.3)
I hope is clear what im trying to attemp
Regards,
- Anonymous4 years ago
Hi JotaEfe ,
My Sample:
I suggest you to try this code to create a calcualted column in Table A.
Asoc. Prod = VAR _Parameter = FILTER ( 'Table C', 'Table C'[ID1] = EARLIER ( 'Table A'[ID] ) ) VAR _PRODUCT2 = ADDCOLUMNS ( _Parameter, "Product2", CALCULATE ( SUM ( 'Table B'[Product2] ), FILTER ( 'Table B', 'Table B'[DATE] = EARLIER ( 'Table A'[DATE] ) ) ) ) RETURN SUMX ( _PRODUCT2, [f] * [Product2] )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 Reply
- AnonymousNot applicable
Hi JotaEfe ,
My Sample:
I suggest you to try this code to create a calcualted column in Table A.
Asoc. Prod = VAR _Parameter = FILTER ( 'Table C', 'Table C'[ID1] = EARLIER ( 'Table A'[ID] ) ) VAR _PRODUCT2 = ADDCOLUMNS ( _Parameter, "Product2", CALCULATE ( SUM ( 'Table B'[Product2] ), FILTER ( 'Table B', 'Table B'[DATE] = EARLIER ( 'Table A'[DATE] ) ) ) ) RETURN SUMX ( _PRODUCT2, [f] * [Product2] )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.