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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Joining tables with Union and different columns

I want to use DAX to UNION 3 tables together. My issue is that 2 of the tables contains split columns...

Table1

ColumnA ColumnB ColumnC

 

Table2

ColumnA ColumnB

 

Table3

ColumnC

 

So normally, I could use 

UNION(
  SELECTCOLUMNS(Table1, "Title", ColumnA, "Name", ColumnB),
  SELECTCOLUMNS(Table2, "Title", ColumnA, "Name", ColumnB)
     )

But how can I incorporate ColumnC from Table1 and from Table3?

I'd like to use DAX and not have to merge via Power Query. 

3 REPLIES 3
tamerj1
Super User
Super User

Hi @Anonymous 

please try

=
UNION (
UNION (
SELECTCOLUMNS (
Table1,
"Title", Table1[ColumnA],
"Name", Table1[ColumnB],
"Value", Table1[Columnc]
),
SELECTCOLUMNS (
Table2,
"Title", Table2[ColumnA],
"Name", Table2[ColumnB],
"Value", BLANK ()
)
),
SELECTCOLUMNS (
Table3,
"Title", BLANK (),
"Name", BLANK (),
"Value", Table3[Columnc]
)
)

Anonymous
Not applicable

for some reason, this produced blank rows for Table3[ColumnC] values that match to Table2[ColumnA] and Table2[ColumnB] - the values for  Table3[ColumnC] did not pull in at all. 

@Anonymous 

Yes it happens sometimes. First adjust the code as follows (make sure the order of the columns in the code is correct)

=
UNION (
SELECTCOLUMNS (
Table1,
"Title", Table1[ColumnA],
"Name", Table1[ColumnB],
"Value", Table1[Columnc]
),
SELECTCOLUMNS (
Table2,
"Title", Table2[ColumnA],
"Name", Table2[ColumnB],
"Value", BLANK ()
),
SELECTCOLUMNS (
Table3,
"Title", BLANK (),
"Name", BLANK (),
"Value", Table3[Columnc]
)
)

 

If this didn't work, copy the code and create a new table then delete the old one. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors