cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate V
Advocate V

Consolidate (Merge Record) Data into a Collection from Local "LoadData" File

the following statement works great. It loads data into a Parts table from a database object. Those items from the database are marked as "Saved",  and then loads data from a local table, and those were previously noted as "Changed".

 

Here is the code:

ClearCollect(Parts,

(AddColumns('[dbo].[vwParts]',"Status","Saved"),

LoadData(Parts,"PartsLocal",true));

 

This works, but the issue is that there are in some cases duplicate rows: Saved and Changed. There could be more "Changed" rows than saved rows, and those are ok. But if there is a Saved Row and a Changed Row with the Same RowId, then those two rows need to be merged into only one row, with the values from the "Changed" superseding those in the "Saved" row.

 

Not certain how to modify the above code to accomplish this.

 

Help is much appreciated.

 

Thank you

1 REPLY 1
Highlighted
Continued Contributor
Continued Contributor

Re: Consolidate (Merge Record) Data into a Collection from Local "LoadData" File

Hi @vsslasd

 

You could theoretically filter the list using the First or Last Function's if the data is in a logical format. I.E. if the Duplicates always go Saved then Changed in the order of the list (You could also maybe sort the List By ID and then Status to give you the correct format for this) After this using Last() to pickup the Second Duplicate will give you a clean list. 

 

If not its a bit more complicated. You could maybe do a clean up job first, using distinct() on the PartsLocal collection, to get a list of ID's and removeif() to clean these out of the Parts collection before you Load the data.

 

A bit complicated but there isn't much duplicate correction in Powerapps just now.

 

Hope this helps,

Nicky

Helpful resources

Announcements
Ignite

Microsoft Ignite

This will be a conference that you do not want to miss!

secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,616)