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

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

Reply
j_w
Helper IV
Helper IV

How to using SQL statement to create a new table base on two exiting tables?

There are two tables in Power BI, Table1 and Table2,

the data of Table1 comes from Database1 in Server1,

the data of Table2 comes from Database2 in Server2.

 

Table1 has columns: ID1, Value1

Table2 has columns: ID2, Value2

 

There is a one-to-one relationship between the two tables: ID1=ID2

 

But IDs in these two tables are not totally matched, for example:

 

Records in Table1:

ID1    Value1

1        A

2        B

3        C

4        D

Records in Table2:

ID2    Value2

1        A

3        C

5        E

 

Is it possible to create a new table Table3 in Power BI using SQL statement or other methods to get the diffrent records in Table1? All the records in Table3 come from Table1.

 

So Table3 should have following records:

2        B

4        D

 

 

Thanks.

 

2 ACCEPTED SOLUTIONS
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @j_w

 

You can do this in a number of places.  In Power BI you can create new tables using this button

 

new table.png

 

And just paste in the following DAX for your example

 

Table 3 = EXCEPT('Table 1','Table 2')

 

result.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

In Power Query you can simply merge (join) the tables with join type left anti (records in Table1 that don't exist in Table2).

 

This video illustrates how the code below is created.

 

let
    Source = Table.NestedJoin(Table1,{"ID1"},Table2,{"ID2"},"NewColumn",JoinKind.LeftAnti),
    #"Removed Columns" = Table.RemoveColumns(Source,{"NewColumn"})
in
    #"Removed Columns"

 

Specializing in Power Query Formula Language (M)

View solution in original post

4 REPLIES 4
j_w
Helper IV
Helper IV

@Phil_Seamark @MarcelBeug

 

Thank you, you are so amazing 🙂

 

Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @j_w

 

You can do this in a number of places.  In Power BI you can create new tables using this button

 

new table.png

 

And just paste in the following DAX for your example

 

Table 3 = EXCEPT('Table 1','Table 2')

 

result.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

You can also do it in SQL but you will probably need a linked server between the two servers for the query to work.

 

There will also be a way you can do it in the Query Editor too @MarcelBeug will probably give you the best approach.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

In Power Query you can simply merge (join) the tables with join type left anti (records in Table1 that don't exist in Table2).

 

This video illustrates how the code below is created.

 

let
    Source = Table.NestedJoin(Table1,{"ID1"},Table2,{"ID2"},"NewColumn",JoinKind.LeftAnti),
    #"Removed Columns" = Table.RemoveColumns(Source,{"NewColumn"})
in
    #"Removed Columns"

 

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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