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
asdf1608
Helper V
Helper V

Need to create union in Power BI

I need ti union two tables from SQL Server in power BI. But the issue is that the number of columns are not same for both the tables. So union()/concadenate() is not possible in Power BI.

So I tried the append and connected to Database.

It is good but the values are wrong. 

 

So there any other ways to union these two tables in Power BI

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

Hi, @asdf1608 

According to your description, you want to union the two tables which has differnt column names.

Here are the steps you can refer to :
This is my test data:

vyueyunzhmsft_0-1674182801939.png

vyueyunzhmsft_1-1674182809438.png

[1]We can crealize it in Power Query Editor. we can create a Blank Query and enter this:

= Table.RenameColumns(#"Table 2",{{"Stu_Name", "Name"}, {"Class_Name", "Class"}}) & #"Table 1"

Then we can get this and you can also remove the column you do not want to in it :

vyueyunzhmsft_2-1674182871241.png

 

[2]We can also realize it in Power Bi Desktop:
We can click "New Table" and enter this:

Table = UNION( SELECTCOLUMNS( ADDCOLUMNS('Table 2',"Teacher", BLANK()) ,"Name",[Stu_Name],"Class",[Class_Name],"Source",[Source],"Teacher",[Teacher]) , 'Table 1')

Then we can also meet your need:

vyueyunzhmsft_3-1674183051751.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

View solution in original post

1 REPLY 1
v-yueyunzh-msft
Community Support
Community Support

Hi, @asdf1608 

According to your description, you want to union the two tables which has differnt column names.

Here are the steps you can refer to :
This is my test data:

vyueyunzhmsft_0-1674182801939.png

vyueyunzhmsft_1-1674182809438.png

[1]We can crealize it in Power Query Editor. we can create a Blank Query and enter this:

= Table.RenameColumns(#"Table 2",{{"Stu_Name", "Name"}, {"Class_Name", "Class"}}) & #"Table 1"

Then we can get this and you can also remove the column you do not want to in it :

vyueyunzhmsft_2-1674182871241.png

 

[2]We can also realize it in Power Bi Desktop:
We can click "New Table" and enter this:

Table = UNION( SELECTCOLUMNS( ADDCOLUMNS('Table 2',"Teacher", BLANK()) ,"Name",[Stu_Name],"Class",[Class_Name],"Source",[Source],"Teacher",[Teacher]) , 'Table 1')

Then we can also meet your need:

vyueyunzhmsft_3-1674183051751.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

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
Top Kudoed Authors