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 / How to insert or updat...
Power Apps
Unanswered

How to insert or update records in a SQL table

(0) ShareShare
ReportReport
Posted on by 8

How do I create a formula that can both update and insert multiple records from a Power Apps collection into an SQL table?

I assume using the ForAll and Patch statements, however my attempts only updates one record in the SQL destination, and neither updates multiple or inserts any rows if they didn't already exist.

PowerApps Collection:

IDTextUpdated Date:
101"Hello everyone"16/11/2020 7:00AM
666"How is your day"16/11/2020 7:00AM
999"Please help!"16/11/2020 7:00AM

 

SQL Table Before:

IDTextUpdated Date:
101"Hello everyone"13/11/2020 11:00AM
123"This is a test"12/11/2020 2:00PM
666"It is good to meet you"14/11/2020 5:00PM


Expected SQL Table After Patch (red font is the new/updated records):

IDTextUpdated Date:
101"Hello everyone"16/11/2020 7:00AM
123"This is a test"12/11/2020 2:00PM
666"How is your day"16/11/2020 7:00AM
999"Please help!"16/11/2020 7:00AM


Below if what I am currently trying (an IF statement) with no luck...

 

 

ForAll(
 [PowerAppCollection],
 If(
 IsBlank(
 LookUp(
 '[SQLTable]',
 [SQLTable].ID = [PowerAppCollection].ID
 )
 ),
 Patch(
 '[SQLTable]',

 Defaults('[SQLTable]'),
 {
 [SQLTable].ID: [PowerAppCollection].ID,
 [SQLTable].Text: [PowerAppCollection]."A new record and some text"
 }
 ),
 Patch(
 '[SQLTable]',
 LookUp(
 '[SQLTable]',
 [SQLTable].ID = [PowerAppCollection].ID
 ),
 {
 [SQLTable].ID: [PowerAppCollection].ID,
 [SQLTable].Text: [PowerAppCollection]."Modified this record"
 }
 )
 )
);

 

 

Categories:
I have the same question (0)
  • Tomirvine Profile Picture
    8 on at

    I have modified my question to included the logic that is currently unsuccessful in working.

    In a collection containing multiple rows to both insert and update others, only one row in the SQL destination is actually updating. No rows are being inserted either.

  • Tomirvine Profile Picture
    8 on at

    As a work-around, I can probably use two separate ForAll statements, one to insert records and the other to update records, but this isn't the ideal solution and probably has speed impacts?

  • Tomirvine Profile Picture
    8 on at

    bump

  • PaulD1 Profile Picture
    2,914 on at

    You might want to try IsEmpty or IsBlankOrError instead of IsBlank. I think I would also specify a 3rd argument in your LookUp for ID (so just the ID column is returned instead of the whole record if it exists, this should improve performance and is more likely that the IsBlankOrError will work).

    PowerApps is a bit odd in how it handles tests for Empties, Blanks and really gets in a muddle over nulls vs blank strings vs empty records/collections and I believe the behaviour can even change depending on whether you have Error Level Formula Management turned on.

    Not sure that is what is causing your issues here, but worth a try... 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard