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 / Faster Way to Patch Mu...
Power Apps
Answered

Faster Way to Patch Multiple Records?

(0) ShareShare
ReportReport
Posted on by

Hi

Can anyone help please?

Is there a more efficient way to update multiple records? I am currently showing a table inside a Gallery and line by line I wish to update a "discount" field. Currently I am using the following:

 

ForAll(Filter(Gallery2.AllItems,

KitID<>"Crewing"),


Patch(QUOTECOLLECTORS,ThisRecord,

{
Discount: GlobalDiscount.Text,
DISCOUNTED_RATES: (LineRate.Text*GlobalDiscount.Text),
DISCOUNTED_TOTALS: (LineRate.Text*(1-GlobalDiscount.Text))*Chargeabledays.Text
}
));

 

This is taking about 10 seconds though to work through each line. Is there a more efficient way? I thought about carrying the ForAll on a local Collection and then patching this back to the data source in one, but I don't seem to be able to do this?

 

Many thanks!

Categories:
  • Chris-D Profile Picture
    1,246 on at

    Hi, 

     

    If you are updating all records, you can use Patch() in a different way. Try this, it's not tested though, let me know if any errors.

     

    With({
     // Select records
     RecordsToUpdate: Filter(Gallery2.AllItems, KitID <> "Crewing")
    },
     // First update records
     UpdateIf( RecordsToUpdate, true, { 
     Discount: GlobalDiscount.Text,
     DISCOUNTED_RATES: (LineRate.Text*GlobalDiscount.Text),
     DISCOUNTED_TOTALS: (LineRate.Text*(1-GlobalDiscount.Text))*Chargeabledays.Text
     });
    
     // Patch records as list
     Patch(QUOTECOLLECTORS,RecordsToUpdate);
    );

     

  • jed76 Profile Picture
    on at

    Many thanks!

     

    Just tried this and I am getting an error that the first argument of UpdateIf should be a collection?

  • Chris-D Profile Picture
    1,246 on at

    Try this?

     

    // Patch records as list
    Patch(
     QUOTECOLLECTORS,
    
     // Create table of records
     ForAll(
    
     // Look rows up from gallery
     Filter(Gallery2.AllItems, KitID <> "Crewing"),
    
     // Update this record with discount info
     Patch( ThisRecord, {
     Discount: GlobalDiscount.Text,
     DISCOUNTED_RATES: (LineRate.Text*GlobalDiscount.Text),
     DISCOUNTED_TOTALS: (LineRate.Text*(1-GlobalDiscount.Text))*Chargeabledays.Text
     })
     )
    );
  • jed76 Profile Picture
    on at

    Think what you just suggested might be it but I am now getting a network error telling me one of the columns is read only? Could we add some kind of showcolumns function to only patch the required ones? Best wishes. 

  • Chris-D Profile Picture
    1,246 on at

    You shouldn't need a ShowColumns() if you're patching straight from a gallery. I posted another way which may work? 

     

    I've had to use ShowColumns() in the past if a collection is ever set to Blank() because Blank() isn't actually blank. 

     

  • jed76 Profile Picture
    on at

    Yes, I've just tried that (it appears to have been deleted from here?) and that is when I am getting the READ ONLY error?

  • jed76 Profile Picture
    on at

    Just tried this, which does something, but not what I want!

     

    Patch(
    QUOTECOLLECTORS,

    ForAll(Filter(Gallery2.AllItems, KitID<>"Crewing") As _item,

    {Discount: GlobalDiscount.Text,
    DISCOUNTED_RATES: (LineRate.Text*GlobalDiscount.Text),
    DISCOUNTED_TOTALS: (LineRate.Text*(1-GlobalDiscount.Text))*Chargeabledays.Text
    }
    )
    );

  • Chris-D Profile Picture
    1,246 on at

    I think some wires may have crossed. Can you try this please? 

    // Patch records as list
    Patch(
     QUOTECOLLECTORS,
    
     // Create table of records
     ForAll(
    
     // Look rows up from gallery
     Filter(Gallery2.AllItems, KitID <> "Crewing"),
    
     // Update this record with discount info
     Patch( ThisRecord, {
     Discount: GlobalDiscount.Text,
     DISCOUNTED_RATES: (LineRate.Text*GlobalDiscount.Text),
     DISCOUNTED_TOTALS: (LineRate.Text*(1-GlobalDiscount.Text))*Chargeabledays.Text
     })
     )
    );
  • jed76 Profile Picture
    on at

    Thanks! I was close but I'd missed out THIS RECORD so it was creating new records rather than updating. Only issue I am getting now is that it is expecting number but getting text in the DISCOUNTED_RATES line.

  • Verified answer
    Chris-D Profile Picture
    1,246 on at

    Your text input boxes are a text data type so you need to use the Value() function to convert to number. 

     

    Value(LineRate.Text) * Value(GlobalDiscount.Text)

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 232 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 202 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard