cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vshah804
Helper I
Helper I

patch the multiple items where condition satisfies

Hello Team, I'm trying to patch the multiple items where condition satisfies but with below formula, It is patching only first item.

 

Patch('[dbo].[Table]',ColumnName1="Text"),{ColumnName2:"YES"})

 

i want to patch all items in ColumnName2 with "YES" where It finds ColumnName1="Text" in dbo].[Table]

 

Please help.

2 ACCEPTED SOLUTIONS

Accepted Solutions
PaulD1
Super User
Super User

For updating multiple records that match a condition, use the UpdateIf function rather tha Patch. Patch is for adding or updating a single record.

To *add* multiple records you can use Collect.

View solution in original post

RandyHayes
Super User III
Super User III

@vshah804 

Consider using the UpdateIf function for this operation. 

UpdateIf will update records based on a criteria.

 

Your formula would be as follows:

UpdateIf('[dbo].[Table]', ColumnName1="Text", {ColumnName2: "YES"})

I hope that is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

8 REPLIES 8
PaulD1
Super User
Super User

For updating multiple records that match a condition, use the UpdateIf function rather tha Patch. Patch is for adding or updating a single record.

To *add* multiple records you can use Collect.

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

Take a look at the following article.  It shows how to patch multiple records in a Batch using Patch and ForAll.

https://powerapps.microsoft.com/en-us/blog/bulk-update-using-forall-and-patch/



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
RandyHayes
Super User III
Super User III

@vshah804 

Consider using the UpdateIf function for this operation. 

UpdateIf will update records based on a criteria.

 

Your formula would be as follows:

UpdateIf('[dbo].[Table]', ColumnName1="Text", {ColumnName2: "YES"})

I hope that is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

Thanks a lot. It works like a charm!:)

Hey Randy, 

Say I wanted to mark a timestamp on a record when the status changes to "Completed". Would it look like this:

UpdateIf(Table, Status = "Completed", {CompletedDate: Today()}) ?

 

I feel like using Today() could be dynamic and it would update the record with the current date every time its opened. Is there a timestamp function I can use to record the date in which the record becomes "completed"?

RandyHayes
Super User III
Super User III

@dataguy33 

Not exactly sure what you are aiming at when you say "...when the status changes to "Completed""

Your formula would go through all the records of the Table where the status IS Completed and set the CompletedDate to the Today() value.  If there is already a CompletedDate in there, it would replace it.

I think you would want something more like: 

   UpdateIf(Table, (Status = "Completed") && IsBlank(CompletedDate), {CompletedDate: Today()})

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes
dataguy33
Frequent Visitor

@RandyHayes 

The objective is to record the exact date when the record status is changed to "completed". I want to be able to automate this so users aren't selecting a CompletedDate manually. 

 

My only concern with that formula, is if a user goes back into a record after it has been updated to completed, and then makes a change, and the record is updated again with a different completed date. 

 

A hard timestamp on the exact date the status changed to completed, with no way of that changing, would be ideal. Does that make a little more sense?

RandyHayes
Super User III
Super User III

@dataguy33 

Yes, so the suggested formula:

   UpdateIf(Table, (Status = "Completed") && IsBlank(CompletedDate), {CompletedDate: Today()})

Would only update items where the date is blank and the status is complete.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (73,462)