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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch() to insert mult...
Power Apps
Answered

Patch() to insert multiple records in one go?

(0) ShareShare
ReportReport
Posted on by
In PowerApps, say I have a button that I want to insert multple records into a table when it's clicked, I know I could just use Patch() multiple times, or have a collection with Patch inside a ForAll(), but that's inefficient, as it will call Patch multiple times, when I could have sworn it was possible to call Patch() in a way that it accepted a table or collection as a parameter and insert all records in one go?

But I can't figure out the syntax.

I should be able to do something like Patch(Source, CollectionOrTable) or Patch(Source, Defaults(Source), CollectionOrTable), shouldn't I?



 
I have the same question (0)
  • Suggested answer
    AmínAA Profile Picture
    1,228 Super User 2025 Season 2 on at
    Greetings CU10011731-0, indeed, you are very much able to patch various records in one go. The easiest way to achieve this would be to do so from a collection or a table, using a structure like this one:
    Patch(Source, Defaults(Source), CollectionOrTable)

    Now, bear in mind that for this to work, the CollectionOrTable should exactly match the scheme of the Source you’re using. So if in the Source you have 10 columns with specific names, that should be the exact same schema of your CollectionOrTable.


    If you like my response, please give it a Thumbs Up. Should this reply solve your question, please mark your post as Solved. Otherwise, feel free to reply to my answer for further help.
    Connect with me if you feel like it! 

  • Verified answer
    WarrenBelz Profile Picture
    153,073 Most Valuable Professional on at
    Depending on your datasource type (I will assume SharePoint here), you can do it with one Patch. ForAll is not designed to be a loop, although it can act that way if it contains an action inside it (as per your example). ForAll creates a Table, which can be Patched in one action to the data source and will run much faster than individual Patches for each record. If it contains the ID of each record, it will update the specific records, if not it will create new records.
    If you only want to update a small number of fields (again for efficiency), then
    Patch(
       SPList,
       ForAll(
      Collection As _Data, { ID: _Data.ID, Field1: _Data.Field1, Field2: _Data.Field2, . . . . . }
      ) )
    For new records, leave out the ID line. I have found (and have responded to a number of posts) that "pushing" a collection directly to a data source can be problematic in some circumstances. Taking the (short) time to write explicit code has its rewards.
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
     
     
     
  • WarrenBelz Profile Picture
    153,073 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn   
  • Ram Prakash Duraisamy Profile Picture
    5,593 Super User 2025 Season 2 on at
    Hi All,
     
    In a single collection with service call you cant patch, instesd try to use FORALL to achieve the same.
  • AmínAA Profile Picture
    1,228 Super User 2025 Season 2 on at
    Greetings @CU10011731-0!
     
    It has been months since you've posted this question. Since you've made no contact I'll be marking @WarrenBelz reply as an answer, as I believe it to be the most complete answer. Please, do let me know if this isn't the case, if you believe I'm wrong, or this didn't solve your problem.
     
    Best regards

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard