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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
IF
Post Prodigy
Post Prodigy

Conditional merge of tables

Hi,

I have two tables. I want to have a combination of the values. If there is a repeated value in both tables, I want to consider the value in the table2. For example; date=03.2021 and Type=A is repeated in both tables. I consider the value in the Table2. I listed the desired result in the TableResult.

Thanks in advance!

Table2

date

type

Value

03.2021

A

40

05.2021

B

21

04.2021

D

50

06.2021

C

40

 

Table1

date

type

Value

03.2021

A

23

03.2021

B

21

04.2021

A

33

04.2021

C

40

 

TableResult

date

type

Value

03.2021

A

40

03.2021

B

21

04.2021

A

33

04.2021

C

40

04.2021

D

50

05.2021

B

21

06.2021

C

40

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @IF 

 

Try below code

let
    Source = Table.NestedJoin(Table1, {"date", "type"}, Table2, {"date", "type"}, "Table2", JoinKind.LeftAnti),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"date", "type", "Value"}),
    #"Appended Query" = Table.Combine({#"Removed Other Columns", Table2}),
    #"Sorted Rows" = Table.Sort(#"Appended Query",{{"date", Order.Ascending}, {"type", Order.Ascending}})
in
    #"Sorted Rows"

082403.jpg

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @IF 

 

Try below code

let
    Source = Table.NestedJoin(Table1, {"date", "type"}, Table2, {"date", "type"}, "Table2", JoinKind.LeftAnti),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"date", "type", "Value"}),
    #"Appended Query" = Table.Combine({#"Removed Other Columns", Table2}),
    #"Sorted Rows" = Table.Sort(#"Appended Query",{{"date", Order.Ascending}, {"type", Order.Ascending}})
in
    #"Sorted Rows"

082403.jpg

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

Anonymous
Not applicable

Sorry, just copy and paste my formula right into a new blank query's formula editor bar. I don't see why you'd need the  subsequent =Source{0}[Merge]

--Nate

Anonymous
Not applicable

In your Join statement, why not use a right anti join to return only rows where Table2 date <> Tabke1 date  and Table2 type <>  Table1 type? Like this:


=Table.NestedJoin(Table2, {"date", "type"}, Table1, {"date", "type"}, "Merged", JoinKind.RightAnti)

 

--Nate

Hi, thanks for the answer. Actually, I didn't understand how to do it. I copied the string that you sent but didn't work. How should I do it? Best

25.jpg

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.