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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
dofrancis3
Helper III
Helper III

UNION fonction (combine columns from two tables)

Dear colleagues,

I need your help :

 

I have TWO tables (OPs_dataset and Population)

  • OPs_dataset= (Country, Year, Total_DP1_12-23)
  • Population= (Country, DJ, HR)

I would like to create a new table (My_Union_Table) which will combine different columns from these two tables.

Below is my Mesure please could you help me to resolve this issue:

My_Union_Table =

UNION(

    SELECTCOLUMNS(

        VALUES(OPs_dataset[Country]),

        "Country", OPs_dataset[Country],

        "Year", SELECTEDVALUE(OPs_dataset[Year]),

        "Gen", "DP1",

        "Age Group", "12-23 months",

        "Mycumul", [Total_DP1_12-23]

    SELECTCOLUMNS(

         VALUES(Population[Country]),

         "Pop_DJ", [DJ]

          "Pop_HR", [HR]

1 ACCEPTED SOLUTION
quantumudit
Super User
Super User

Hello @dofrancis3 

It would have been beneficial if you had provided a sample dataset your query along with the expected dataset. Nevertheless, have created a sample dataset based on the information.

 

Here is the OPs_dataset

quantumudit_2-1739362722138.png

 

Here is the Population data:

quantumudit_3-1739362741351.png

 

Union of Tables

 

If you need combine or append these tables one below the other, you must follow the approach mentioned by

 @powerbidev123 

 

Here is the formatted DAX formula to create a new calculated table:

 

My_Union_Table (Appended) = 
UNION (
    SELECTCOLUMNS (
        OPs_dataset,
        "Country", OPs_dataset[Country],
        "Year", OPs_dataset[Year],
        "Gen", "DP1",
        "Age Group", "12-23 months",
        "Mycumul", OPs_dataset[Total_DP1_12-23],
        "Pop_DJ", BLANK (),
        "Pop_HR", BLANK ()
    ),
    SELECTCOLUMNS (
        Population,
        "Country", Population[Country],
        "Year", BLANK (),
        "Gen", BLANK (),
        "Age Group", BLANK (),
        "Mycumul", BLANK (),
        "Pop_DJ", Population[DJ],
        "Pop_HR", Population[HR]
    )
)

 

Here is the screenshot of the solution table that you can expect from the above calculated table DAX formula : 

quantumudit_0-1739362348612.png

If this is the result you want then kindly accept @powerbidev123  reply as the solution

 

Join of Tables

 

However, if you wish to join the tables based on the country column to retrieve the remaining data, you may use the following DAX formula.

 

My_Union_Table = 
NATURALINNERJOIN ( OPs_dataset, SELECTCOLUMNS ( Population, [DJ], [HR] ) )

 

Here is the screenshot of the table that the above DAX will generate:

quantumudit_1-1739362518456.png

 

I am also attaching the Power BI file for your reference.

 

Best Regards,
Udit

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
Visit My Linktree: LinkTree

 

Proud to be a Super User

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thanks for the reply from quantumudit  and powerbidev123, please allow me to provide another insight:

Hi, @dofrancis3 
Thanks for reaching out to the Microsoft fabric community forum.
 

Could you please let me know if the responses from quantumudit  and powerbidev123 have resolved your issue?If it did, kindly accept it as the solution.

vlinyulumsft_0-1739502474791.png

I believe both quantumudit  and powerbidev123's suggestions are very effective. quantumudit's response is particularly detailed, while powerbidev123's idea is concise and clear. Their answers align with the format requirements of the UNION function, especially the restriction that both tables must have the same number of columns. Below is a screenshot from the official documentation to help with your understanding:

vlinyulumsft_1-1739502474792.png

For more details, please refer to the documentation:

https://learn.microsoft.com/en-us/dax/union-function-dax#remarks

 

Power Query also has a similar feature called "Append Queries":

vlinyulumsft_2-1739502561599.png

 For more details, please refer to the documentation:

 Append queries - Power Query | Microsoft Learn


Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

quantumudit
Super User
Super User

Hello @dofrancis3 

It would have been beneficial if you had provided a sample dataset your query along with the expected dataset. Nevertheless, have created a sample dataset based on the information.

 

Here is the OPs_dataset

quantumudit_2-1739362722138.png

 

Here is the Population data:

quantumudit_3-1739362741351.png

 

Union of Tables

 

If you need combine or append these tables one below the other, you must follow the approach mentioned by

 @powerbidev123 

 

Here is the formatted DAX formula to create a new calculated table:

 

My_Union_Table (Appended) = 
UNION (
    SELECTCOLUMNS (
        OPs_dataset,
        "Country", OPs_dataset[Country],
        "Year", OPs_dataset[Year],
        "Gen", "DP1",
        "Age Group", "12-23 months",
        "Mycumul", OPs_dataset[Total_DP1_12-23],
        "Pop_DJ", BLANK (),
        "Pop_HR", BLANK ()
    ),
    SELECTCOLUMNS (
        Population,
        "Country", Population[Country],
        "Year", BLANK (),
        "Gen", BLANK (),
        "Age Group", BLANK (),
        "Mycumul", BLANK (),
        "Pop_DJ", Population[DJ],
        "Pop_HR", Population[HR]
    )
)

 

Here is the screenshot of the solution table that you can expect from the above calculated table DAX formula : 

quantumudit_0-1739362348612.png

If this is the result you want then kindly accept @powerbidev123  reply as the solution

 

Join of Tables

 

However, if you wish to join the tables based on the country column to retrieve the remaining data, you may use the following DAX formula.

 

My_Union_Table = 
NATURALINNERJOIN ( OPs_dataset, SELECTCOLUMNS ( Population, [DJ], [HR] ) )

 

Here is the screenshot of the table that the above DAX will generate:

quantumudit_1-1739362518456.png

 

I am also attaching the Power BI file for your reference.

 

Best Regards,
Udit

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
Visit My Linktree: LinkTree

 

Proud to be a Super User

powerbidev123
Solution Sage
Solution Sage

Hi @dofrancis3 ,

Union only works with tables of the same column structure. Your two SELECTCOLUMNS statements must have the same column names.

 

Please check below DAX:

 

My_Union_Table =
UNION(
SELECTCOLUMNS(
OPs_dataset,
"Country", OPs_dataset[Country],
"Year", OPs_dataset[Year],
"Gen", "DP1",
"Age Group", "12-23 months",
"Mycumul", OPs_dataset[Total_DP1_12-23],
"Pop_DJ", BLANK(),
"Pop_HR", BLANK()
),
SELECTCOLUMNS(
Population,
"Country", Population[Country],
"Year", BLANK(),
"Gen", BLANK(),
"Age Group", BLANK(),
"Mycumul", BLANK(),
"Pop_DJ", Population[DJ],
"Pop_HR", Population[HR]
)
)

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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