cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
bhorvati Frequent Visitor
Frequent Visitor

Merge queries. How replace a row?

 

I have two queries with the exact same columns.  I would like to replace one row record in my main data table with a row record from a second table.  I have an index column in both tabels.  I woud like to replace index row 23655 in my main data table with row 23655 in my 2nd data table.  How would I acoomplish this?  I thought merge would work, but I can't figure it out.

 

merge.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
ImkeF
MVP

Re: Merge queries. How replace a row?

If my understanding of the problem is correct, this would probably be the easiest option:

 

1) Append the long table to your table that holds the replacements

2) Check the index column and remove duplicates

 

Removing duplicates will keep the first row it finds in a table. This should also be fast.

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Imke Feldmann

How to integrate M-code into your solution -- Check out more PBI- learning resources here -- Performance Tipps for M-queries




View solution in original post

6 REPLIES 6
stretcharm Senior Member
Senior Member

Re: Merge queries. How replace a row?

You could filter out the row in the main query and then use append queries to add the row from the 2nd.

bhorvati Frequent Visitor
Frequent Visitor

Re: Merge queries. How replace a row?

@stretcharm  Thanks.  Yes that would work, but I could potentially have a few hundred random rows I would like to replace and I would like to find a more automated solution where the rows in one table could simple replace the rows in the other table and use the index column as the common column to identify which rows to replace.  

stretcharm Senior Member
Senior Member

Re: Merge queries. How replace a row?

You can use a Left Anti to get a data set from the first list that doesnt have rows in the 2nd then append the 2nd.

 

You could also create a function to replace values, but I suspect this will be very slow on a large dataset.

https://msdn.microsoft.com/en-us/query-bi/m/table-replacevalue

 

This is a useful blog from @cwebb  that uses Table.AddKey to improve merge performance.

https://blog.crossjoin.co.uk/2018/03/16/improving-the-performance-of-aggregation-after-a-merge-in-po...
https://msdn.microsoft.com/query-bi/m/table-addkey


ImkeF
MVP

Re: Merge queries. How replace a row?

If my understanding of the problem is correct, this would probably be the easiest option:

 

1) Append the long table to your table that holds the replacements

2) Check the index column and remove duplicates

 

Removing duplicates will keep the first row it finds in a table. This should also be fast.

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Imke Feldmann

How to integrate M-code into your solution -- Check out more PBI- learning resources here -- Performance Tipps for M-queries




View solution in original post

Community Support Team
Community Support Team

Re: Merge queries. How replace a row?

Hi @bhorvati

a more automated solution where the rows in one table could simple replace the rows in the other table and use the index column as the common column to identify which rows to replace

To achieve this, we need know the which the rule of replacing, this is to say, which rows should be replaced, can this follow a common condition?

 

Additionally, i have found a very helpful article, hope it can help you!

 

Best Regards

Maggie

 

bhorvati Frequent Visitor
Frequent Visitor

Re: Merge queries. How replace a row?

Thanks @v-juanli-msft, but my the records I need to replace do not have consistent fields that need to be replaced, but thanks for reference provided (good info).  

 

My situation is i have a large data table and some of the records in that data table need to be modified.  The records might have a wrong plant listed or a wrong material listed, so i needed a way to have those individual records replaced with records from another table that have the correct fields.  

Helpful resources

Announcements
New Kudos Received Badges Coming

New Kudos Received Badges Coming

Kudos to you if you earned one of these! Check your inbox for a notification.

Microsoft Implementation for Communities Wins Award

Microsoft Implementation for Communities Wins Award

Learn about the award-winning innovation that was implemented across Microsoft’s Business Applications Communities.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Kudoed Authors (Last 30 Days)
Users online (1,078)