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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
jaryszek
Super User
Super User

Upsert Query in power query

Hi Guys,

 

i am looking for equivalent for upsert query like here:

https://www.access-programmers.co.uk/forums/threads/append-if-rows-do-not-exists-else-update-if-exis... 

 

Ok user has table here - TableInput:

IDAnimalColor
1DogGreen
2CatWhite

 

and in core model i have tableToCompare:

IDAnimalColor
1DogGreen
2CatBlack
3MouseRed

 

But what i want to get is:

 

IDAnimalColor
1DogGreen
2CatWhite
3MouseRed

 

so row with ID = 3 was inserted into InputTable because does not exists in tableToInput. 
And Cat which was updated in TableToInput by user to White i am keeping. So this row has been updated from black (TableToCompare) to white (TableInput). 

 

How to do this kind of operation in power query? (not power BI)

 

Please help

 

Best,
Jacek

1 ACCEPTED SOLUTION
HotChilli
Community Champion
Community Champion

Create one custom column with the logic to select the "right" Color.

Fix the  datatypes on the columns.  You don't need to return the ID and Animal if they don't change.

If it works, it works.

View solution in original post

5 REPLIES 5
HotChilli
Community Champion
Community Champion

Create one custom column with the logic to select the "right" Color.

Fix the  datatypes on the columns.  You don't need to return the ID and Animal if they don't change.

If it works, it works.

Thank you so much for tipping me,

 

Best,
Jacek

jaryszek
Super User
Super User

What i did as your suggestion is:

 

let
    Source = Excel.CurrentWorkbook(){[Name="TableToCompare"]}[Content],
    #"Merged Queries" = Table.NestedJoin(Source, {"ID"}, TableInput, {"ID"}, "TableInput", JoinKind.LeftOuter),
    #"Expanded TableInput" = Table.ExpandTableColumn(#"Merged Queries", "TableInput", {"ID", "Animal", "Color"}, {"TableInput.ID", "TableInput.Animal", "TableInput.Color"})
in
    #"Expanded TableInput"

 

and  what i got:

jaryszek_0-1640087642787.png

 

And now just create custom columns and check if they are the same? 
No better way? 

 

Best,
Jacek

 

jaryszek
Super User
Super User

thanks HotChilli. 

what you mean by column of color ? 

 

Best,
Jacek

 

HotChilli
Community Champion
Community Champion

you could start from tableToCompare and perform a merge (left outer) with TableInput on ID field.

You could then decide which column of color you prefer 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

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.