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

Merge two tables if the key does NOT match

Hi there,

I have one table with historic order information with order number as a primary key. It contains detailed order information

My second table also has order information with order number as a primary key. It contains limited order information.

 

I want to add all rows from the second table to the first table with just one rule:

If the order number already exists in the first table, then do not return any information from the second table. Or the other way around; if the order number exists in the second table but not in the first table, then add the row from the second table with that order number to the first table.

 

Would anyone know how to handle this?

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

HI @Anonymous,

 

I'd like to suggest you use except function to extract unmatched orderid between table1 and table2, then use union and filter function to union two tables.


Sample formula:

New Table =
VAR idlist =
    EXCEPT ( VALUES ( Table2[OrderID] ), VALUES ( Table1[OrderID] ) )
RETURN
    UNION ( Table1, FILTER ( Table2, [OrderID] IN idlist ) )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Anonymous,

 

I'd like to suggest you use except function to extract unmatched orderid between table1 and table2, then use union and filter function to union two tables.


Sample formula:

New Table =
VAR idlist =
    EXCEPT ( VALUES ( Table2[OrderID] ), VALUES ( Table1[OrderID] ) )
RETURN
    UNION ( Table1, FILTER ( Table2, [OrderID] IN idlist ) )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Hi @v-shex-msft,

Thanks for getting me on the right way, that actually worked! Thanks for helping out & happy holidays!

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.