Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
HamidBee
Power Participant
Power Participant

Problem Creating a table using columns from different tables (DAX)

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. 

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @HamidBee 

 

Calculatetable is not used to connect tables, so the latter code has no effect.

CALCULATETABLE function (DAX) - DAX | Microsoft Docs

vjaneygmsft_0-1641279415414.png

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:

 

vjaneygmsft_1-1641280468275.png

vjaneygmsft_2-1641280481403.png

Below is my sample.

Did I answer your question ? Please mark my reply as solution. Thank you very much.
 If not, please feel free to ask me.
 
Best Regards,
Community Support Team _ Janey

View solution in original post

4 REPLIES 4
v-janeyg-msft
Community Support
Community Support

Hi, @HamidBee 

 

Calculatetable is not used to connect tables, so the latter code has no effect.

CALCULATETABLE function (DAX) - DAX | Microsoft Docs

vjaneygmsft_0-1641279415414.png

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:

 

vjaneygmsft_1-1641280468275.png

vjaneygmsft_2-1641280481403.png

Below is my sample.

Did I answer your question ? Please mark my reply as solution. Thank you very much.
 If not, please feel free to ask me.
 
Best Regards,
Community Support Team _ Janey
AlexisOlson
Super User
Super User

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?

 

bcdobbs
Community Champion
Community Champion

I think you want UNION instead of calculatetable.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

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

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors