Forum Discussion
NATURALLEFTOUTERJOIN not finding common join columns
- 1 year ago
tchiang7 You can join those tables by breaking the lineage for numeric columns use +0 for text use & ""
Join Sales & Product = VAR SalesTable = SELECTCOLUMNS ( Sales, "ProductKey", Sales[ProductKey] + 0, Sales[Quantity], Sales[Net Price] ) VAR ProductsTable = SELECTCOLUMNS ( 'Product', "ProductKey", 'Product'[ProductKey] + 0, 'Product'[Brand], 'Product'[Color] ) VAR Result = NATURALLEFTOUTERJOIN ( SalesTable, ProductsTable ) RETURN Result - 1 year ago
There is another way of solving this, since JOIN functions expect same column names and same lineage but 2 Key column from different tables do not have the same lineage, even if they are connected through a relationship.
In this scenario adding 0 or "" disconnects their lineage from the model and they both act as columns that don't exists in the model so JOIN functions work fine.
However to make the lineage of both columns same we can use TREATAS which actually Treats one or more columns as the columns of some other tables.
Join Sales & Products TREATAS = VAR SalesTable = SELECTCOLUMNS ( Sales, Sales[ProductKey], Sales[Quantity], Sales[Net Price] ) VAR ProductsTable = TREATAS ( SELECTCOLUMNS ( 'Products', 'Products'[ProductKey], 'Products'[Brand], 'Products'[Color] ), Sales[ProductKey], Products[Brand], Products[Color] ) VAR Result = NATURALLEFTOUTERJOIN ( SalesTable, ProductsTable ) RETURN ResultSo for the duration of the calculation Products[ProductKey] will be treated as Sales[ProductKey].
Thank you for the answer. It is working.