web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch function duplica...
Power Apps
Answered

Patch function duplicates records

(0) ShareShare
ReportReport
Posted on by 6

Hello,

 

This subject has already been mentioned but I can't find the right answer :

https://powerusers.microsoft.com/t5/Building-Power-Apps/Duplicate-records-adding-from-collection-to-database/m-p/897661#M284903

https://powerusers.microsoft.com/t5/Building-Power-Apps/Bulk-patch-creating-duplicate-records/m-p/771407#M245798

 

I have an app that's supposed to add/remove text records in an Excel Sheet in OneDrive.

 

To do that in a batch way, I store my sheet in a collection then Patch that collection to the original data source.

Data source Sheet : "Fériés" with column "Dates"

Collection : "JoursNonTravailles" with column "Dates"

 

OnStart : ClearCollect(JoursNonTravailles;Fériés.Dates)

 

Then I do the changes. Then Patch :

Patch(Fériés;Fériés.Dates;JoursNonTravailles.Dates)

 

It then reuploads the entire collection to the sheet, no matter if the records already exist or not.

 

I have a feeling I would need to clear the whole sheet before patching my collection into it, but I don't know the right formula to do so.

 

Thanks a lot in advance for your help,

 

PowFlow

Categories:
I have the same question (0)
  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @PowFlow I tried the same and it just seems to update rather than reload the whole thing. How is the structure of the Excel file?

  • v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @PowFlow,

    Based on the issue that you mentioned, do you want to edit records in the Excel table?

    Could you please tell me that you wan to duplicate the records or update the records?

    The formula you provided will update the Fériés with the duplicated records. If you just want to make the whole collection cover the records in the Excel table, I think you should change your problem-solving ideas.

    If you want to update some certain records, you could use the Gallery and the Edit form.

    Add a Gallery and an Edit Form

    Set the Gallery with your Excel table name

    Set the Gallery OnSelect as below:

    Navigate(EditForm1)

    Set the Edit Form Item as below:

    Gallery1.Selected

    Add a submit button and set the OnSelect as below:

    SubmitForm(EditForm1)

    Once you select a record from the Gallery, it will navigate you to the edit form and you could update the date.

    Check if it could help you.

    Regards,

    Qi

  • PowFlow Profile Picture
    6 on at

    Thanks for your replies !

    Here's the Excel Table : (Dates in text format)

    PowFlow_0-1621929349563.png

     

    @v-qiaqi-msftthe issue is that I only add / delete records, it's not really an update. I think the only way to do it right is to remove all the records in the table and then Patch the collection in the Excel Sheet.

     

    To simplify, I chose to update directly the data source rather than the collection, it takes a little more time but it is more dynamic. And it works 🙂

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @PowFlow,

    Have your solved you problem?

    I have a test on my side, please take a try as below.

    1). Set the OnVisible property of the current screen as below:

    ClearCollect(Tem,Table1)

    2). Add a Gallery, insert a Text input and X icon, set the Items property of the Gallery as below:

    Tem

    Set the OnSelect property of the X icon as below:

    Remove(Tem,ThisItem) // You could click it to delete a record from the collection

    3). Add a + icon outside the Gallery, set the OnSelect property of the Button control as below:

    Collect(Tem,CountRows(Tem)) // You could click it to add a record to the collection

    4). Add a Button and set the OnSelect property:

    RemoveIf(Table1,true) // You could click it to delete all the records from the Excel table

    5). Add a Button and  set the OnSelect property:

    ForAll(Gallery4.AllItems,Patch(Table1,Defaults(Table1),{Code:TextInput3.Text}))

    Check the Gif as below:delete.gif

    Regards,

    Qi

  • PowFlow Profile Picture
    6 on at

    Thank you for your very detailed answer @v-qiaqi-msft !

     

    It works fine for me ! However, doing it I realized it was taking longer to delete / reupload the whole Excel Table than to upload / remove the records one by one depending on the OnSelect property.

     

    I used that code to do it directly in the Excel Sheet :

    If(
     CountRows(
     Search("My Excel Table";Text(ThisItem.Value;ShortDate);"Dates"))>0;
     Remove("My Excel Table";Search("My Excel Table";Text(ThisItem.Value;ShortDate);"Dates"));
     Collect("My Excel Table";{Dates : Text(ThisItem.Value;ShortDate)})
     )

     

    However I'm kind of new to using the power platform, is there a better way to use lists and tables than Excel 365 ? Like Sharepoint Lists for example ? I see them quoted a lot in the topics.

     

    Thanks again for your answer ! I've accepted it as a solution as it works fine for me 🙂

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 401 Most Valuable Professional

#2
11manish Profile Picture

11manish 201 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard