Skip to main content

Notifications

Community site session details

Community site session details

Session Id : S0xpVNQQaa0s4yJ5aqiDhM
Power Apps - Building Power Apps
Answered

(confusion) ThisRecord when used in a LookUp to evaluate an expression keeps returning the first record.

Like (0) ShareShare
ReportReport
Posted on 24 Aug 2023 04:42:24 by 29

Scenario: I have 2 collections.

 

Collection A { name: string , age: int }

Collection B { name: string, address: string }

 

If I try to loop through Collection A (using ForAll), and then use a LoopUp to search Collection B by comparing names are equal, such as the below -

 

ForAll('Collection A', CustomFunctionDoSomething.Run(LookUp('Collection B', name=ThisRecord.name).address))

The above will always return the very first record from Collection B for all records in Collection A.

Resulting in all names having the same address.

I have thought about the reasons why, but nothing makes sense, is this a bug?

  • Verified answer
    Inogic Profile Picture
    983 Super User 2025 Season 1 on 24 Aug 2023 at 08:47:07
    Re: (confusion) ThisRecord when used in a LookUp to evaluate an expression keeps returning the first record.

    Hi @power-apps-user 

    It's not a bug, actually it includes concept of scope that when we use nested functions with ForAll such as Patch(), Collect() or If condition etc. then it cannot find the reference from outer scope. That is the reason we need to use either As or "Collection[@column]".

    Please refer to the below link for the same.

    https://powerapps.microsoft.com/en-us/blog/formulas-thisrecord-as-and-sequence/ 

    Thanks!

     

    Inogic Professional Services Division

    Power Platform and Microsoft Dynamics 365 CRM Development – All under one roof!

    Drop an email at crm@inogic.com

    Services:  http://www.inogic.com/services/

    Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/

  • power-apps-user Profile Picture
    29 on 24 Aug 2023 at 06:32:58
    Re: (confusion) ThisRecord when used in a LookUp to evaluate an expression keeps returning the first record.

    Hello Inogic, 

    My solution was to use 'As', which fixes this issue. However this took a few hours of testing before I found the problem and solution. i.e. -

    ForAll('Collection A' As _ColA, CustomFunctionDoSomething.Run(LookUp('Collection B', name=_ColA.name).address))


    My intention above was to find out if this issue was my incorrect knowledge of how ThisRecord works, or that this was a bug.



  • Inogic Profile Picture
    983 Super User 2025 Season 1 on 24 Aug 2023 at 06:16:53
    Re: (confusion) ThisRecord when used in a LookUp to evaluate an expression keeps returning the first record.

    Hi @power-apps-user 

    You can try below formula for forall in your canvas app,

    ForAll('Collection A', CustomFunctionDoSomething.Run(LookUp('Collection B', name=CollectionA[@name]).address))

    Thanks!

     

    Inogic Professional Services Division

    Power Platform and Microsoft Dynamics 365 CRM Development – All under one roof!

    Drop an email at crm@inogic.com

    Services:  http://www.inogic.com/services/

    Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/




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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard
Loading started