Forum Discussion
Conditional Column based on Matching Column in another Table
- 5 years ago
Hi, mpribadi07
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table1:
Table2:
Relationship(Many to Many):
You may create a calculated column as below.
Result Column = var wic = [WIC] return IF( [Ship To]="DC 04", "DOT COM", CONCATENATEX( FILTER( Table1, [WIC]=wic ), [Opstudy], "," ) )Result:
Or you may try the following calculated table.
Table = ADDCOLUMNS( SUMMARIZE( Table2, Table2[WIC], "Ship To", CONCATENATEX( Table2, [Ship To], "," ) ), "Result", var wic = [WIC] return IF( [Ship To]="DC 04", "DOT COM", CONCATENATEX( FILTER( Table1, [WIC]=wic ), [Opstudy], "," ) ) )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Marsha,
Please @ mention me or I'll miss your replies. Type @ then select my name.
The data you provided would have a 1-1 relationship. You should avoid M-M. My code won't work for M-M.
Can you change your tables so that they have 1-1 or 1-M?
Looking at Table2 I'd expect that to have unique entries for WIC as I'd expect you can only ship to a single DC?
Your stated logic is
If "Ship To" = DC 04, print "DOT COM"
Else -> Return the corresponding "Opstudy" value from Table 1 based on the matching WIC.
But if a WIC value appears multiple times in Table1 there is no corresponding Opstudy value. There are multiple matching values. How to know which one to use?
The values in WIC column of Table 1 need to unique in that column.
Regards
Phil