We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
I am using the following code to join 4 columns from two different tables:
CALCULATETABLE(
SELECTCOLUMNS('2020',"values",'2020'[Value],"Dates",'2020'[Dates]),
SELECTCOLUMNS('2021',"values",'2021'[Value],"Dates",'2021'[Dates])
)
Strangely it only returns table '2020' columns. The '2021' columns do not appear. I think there may be something wrong with my code I just found it strange that Power BI did not detect any errors in the code.
Any help is appreciated.
Solved! Go to Solution.
Hi, @HamidBee
Calculatetable is not used to connect tables, so the latter code has no effect.
CALCULATETABLE function (DAX) - DAX | Microsoft Docs
Calculatetable and Union function both will create a new table.
Like this:
Table =
UNION (
SELECTCOLUMNS ( '2020', "values", '2020'[Value], "Dates", '2020'[Dates] ),
SELECTCOLUMNS ( '2021', "values", '2021'[Value], "Dates", '2021'[Dates] )
)
This table can be displayed in the desktop as a new table, or as a variable table in the measure.
If you don't want to add the third table, you can easily append them in PowerQuery.
Like this:
Below is my sample.
Hi, @HamidBee
Calculatetable is not used to connect tables, so the latter code has no effect.
CALCULATETABLE function (DAX) - DAX | Microsoft Docs
Calculatetable and Union function both will create a new table.
Like this:
Table =
UNION (
SELECTCOLUMNS ( '2020', "values", '2020'[Value], "Dates", '2020'[Dates] ),
SELECTCOLUMNS ( '2021', "values", '2021'[Value], "Dates", '2021'[Dates] )
)
This table can be displayed in the desktop as a new table, or as a variable table in the measure.
If you don't want to add the third table, you can easily append them in PowerQuery.
Like this:
Below is my sample.
CALCULATETABLE expects a table for the first argument and filters for any additional arguments, so the 2021 columns are being used as filters on the 2020 columns (which doesn't change anything if these tables are unrelated). This is valid DAX even if it isn't doing what you expect it to.
From the names of the columns you've assigned, I would have assumed you wanted to union these (like @bcdobbs assumed) but, apparently, you want something else. What is the result you're expecting instead?
The issue I'm having with UNION is that it appends the table. I couldn't find a work around for it. Any suggestions? Also is it not possible for CALCULATETABLES to be used to join two columns from differnet tables together?
Thanks
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 53 | |
| 38 | |
| 33 | |
| 15 | |
| 15 |
| User | Count |
|---|---|
| 66 | |
| 63 | |
| 37 | |
| 34 | |
| 22 |