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 / Loop through records i...
Power Apps
Answered

Loop through records in a collection and update each record

(1) ShareShare
ReportReport
Posted on by 50

I have a collection called 'colYearGroup' which contains about 10 rows. In the collection, there is a column called 'Paper' and a column called 'Test', and an empty column called 'Marks'.

 

I need to loop through the collection and update the 'Marks' column by looking up a value from another collection called 'colTestLookup' - which holds the number of marks for any test and paper combination.

 

So I basically need to loop through the collection, and update one column of the record.

 

ForAll(
 colYearGroup As data,
 If(
 And(YGSelectSubject.Selected.Value = "Maths", YGSelectAspect.Selected.Value="Number"),
 Patch(
 colYearGroup,
 LookUp(colYearGroup,And(Paper=data.Paper,Test=data.Test)),
 {
 Marks: Text(LookUp(colTestLookup,And(Test=data.Test,Paper=data.Paper),Marks)) 
 }
 )
 );
);

 

However, using this code, where I try to loop through the collection, and patch the current record, I get the error:
'This function cannot be used on the same data source that is used in ForAll'. Which is telling me I can't patch the record I'm on.

 

How can I Ioop through a collection and update each record in the loop?

Categories:
  • Verified answer
    Michael E. Gernaey Profile Picture
    53,970 Super User 2026 Season 2 on at

    Hi @mrwilliams 

     

    Hi, there are several ways but I am omw to Ikea lol.

     

    So here is the quickest change.

     

    ClearCollect(_colYearGroup, colYearGroup );
    
    ForAll(
     _colYearGroup As data,
     If(
     And(YGSelectSubject.Selected.Value = "Maths", YGSelectAspect.Selected.Value="Number"),
     Patch(
     colYearGroup,
     LookUp(colYearGroup,And(Paper=data.Paper,Test=data.Test)),
     {
     Marks: Text(LookUp(_colYearGroup, And(Test=data.Test,Paper=data.Paper),Marks)) 
     }
     )
     );
    );

     


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

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 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 271

#3
Mohsin Ali Profile Picture

Mohsin Ali 223

Last 30 days Overall leaderboard