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

How to update all records in a column based on condition?

Hi. Suppose I have a table called "My Table" like this:

ID(Auto generated)Ball NumberStudent_IDItem_IDValue
12123412 
2 234513 

 

I'd like to patch the "Value" column of all the records based on whether the "Ball Number" column is blank. If it is blank, the "Value" should be Concatenate(Student_ID, Item_ID), but if it is not blank, the "Value" should be just the Student_ID.

 

I tried to use the following formula to achieve what I want:

 

ForAll('My Table', Patch('My Table', LookUp('My Table', ID=ThisRecord.ID), {

Value: If(!IsBlank(ThisRecord.'Ball Number'), ThisRecord.Student_ID, Concatenate(ThisRecord.Student_ID, ThisRecord.Item_ID))

}

 

But it keeps telling me "the function cannot operate on the same datasource that is used in Forall". I have read https://powerusers.microsoft.com/t5/Building-Power-Apps/Patch-the-same-data-source-as-in-Forall-loop... but I still have no idea how to make my code work. Can anyone help me? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User
Super User

@CUCOOPE 

Rather than call ForAll, you can call UpdateIf to do a conditional update.

https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-update-updateif

 

UpdateIf('My Table',
         IsBlank('Ball Number'),
         {Value:Concatenate(Student_ID, Item_ID)}
)

View solution in original post

2 REPLIES 2
timl
Super User
Super User

@CUCOOPE 

Rather than call ForAll, you can call UpdateIf to do a conditional update.

https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-update-updateif

 

UpdateIf('My Table',
         IsBlank('Ball Number'),
         {Value:Concatenate(Student_ID, Item_ID)}
)

Thanks!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,331)