Power Query Replace values through Merge

absherzad

New Member
Joined
Jun 19, 2017
Messages
42
Hi everyone,
I have two tables. Let us call them TableA and TableB.
I imported both of into Power Query as connection only query. Then I created a reference from TableA and Merged it with TableB using Left Outer Join Type.

Now I want
to replace specific value for a column in TableA with value for a column from TableB for the matched records. What is the optimal approach of doing this?

Please see the Screenshot for better clarification.

 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I have the following solution but I am afraid it is not the optimal one:

Code:
let
    Source = TableA,
    #"Merged Queries" = Table.NestedJoin(Source,{"Code"},TableB,{"Code"},"NewColumn",JoinKind.LeftOuter),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Rank"}, {"NewColumn.Rank"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded NewColumn", "MergedReplaced", each if [NewColumn.Rank] = null then [Rank] else [NewColumn.Rank] )
in
    #"Added Conditional Column"
 
Last edited:
Upvote 0
Here is another alternative solution for SQL users:

Code:
UPDATE TableA JOIN TableB USING (Code) SET TableA.Rank = TableB.Rank;
 
Upvote 0

Forum statistics

Threads
1,215,365
Messages
6,124,513
Members
449,168
Latest member
CheerfulWalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top