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 / Patch within ForAll wi...
Power Apps
Answered

Patch within ForAll with LookUp with Field = ThisRecord.Field issue

(0) ShareShare
ReportReport
Posted on by 732

I have this code:

Patch(
 'Student List',
 LookUp('Student List', 'User ID' = ThisRecord.'User ID'),
 {Carnet: LookUp('Student List','User ID' = ThisRecord.'User ID',Carnet) - 1}
)

I think the issue is the 'User ID' = ThisRecord.'User ID' as it always returns the first record in the table. In other cases I usually make sure the field names aren't the same in the collection / table that the ForAll is processing on but in this case I didn't and it would be cumbersome to fix. Before copying the column to another named column I wanted to see if there was something I was missing.

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @BrianHFASPS 

    Your formula (Lookup) will only return the first record.  ThisRecord is going to refer to the Student List record.  And, that will always be equal for each record, so the first will only be returned.

     

    What is it that you are trying to do in this formula?

    What are you trying to look up?

  • Verified answer
    BrianHFASPS Profile Picture
    732 on at

    I thought ThisRecord would return the row off the currently being acted upon ForAll loop, I guess not.

    I did this:

    Collect(TempAttRoster,(RenameColumns(Roster,"User_x0020_ID","TempID")));

    After which my code becomes:

    Patch(
     'Student List',
     LookUp('Student List', 'User ID' = TempID),
     {Carnet: LookUp('Student List','User ID' = TempID) - 1}
    )

    It shouldn't cause issues now. I have a collection of students and I am doing processing on that list. It is just that the column name in the collection is the same as the table I am trying to patch and causes a circular reference. In most cases I was careful to name the unique ID column different in tables or collections and I just goofed on this one and tried to take a shortcut. 

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @BrianHFASPS 

    If you are using that Patch IN a ForAll, you are using is backwards and are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

    It is more efficient to use the function as intended and will provide better performance especially when Patching.  This will present the more horrific performance of all.

     

    Construct should be:

    Patch(yourDataSource,
     ForAll(....
    )

     

    If you are using:

    ForAll(...
     Patch(...

    It is backwards and going to kill your performance!

     

    Then you can use As to name your ForAll values for use in your Lookup.

    i.e.

    Patch('Student List',
     ForAll(yourTable As _item,
     With(LookUp('Student List', 'User ID' = _item.'User ID'),
     {ID: ID,
     Carnet: Carnet - 1
     }
     )
     )
    )

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 421 Most Valuable Professional

#2
11manish Profile Picture

11manish 153 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 116 Super User 2026 Season 2

Last 30 days Overall leaderboard