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 / Combining Multiple 'Up...
Power Apps
Answered

Combining Multiple 'UpdateContext' Into a Single One Does Not Always Seems to Properly Set Values

(0) ShareShare
ReportReport
Posted on by 9

Hello:

 

Below is how I typically set multiple local context variables via the "UpdateContext" function per Microsoft's recommendation for efficiency:

 

UpdateContext(
 {
 filteredHistory:Filter(ResourcesHistory,ResourceID=currentResource.ResourceID).ArchivedOn,
 distinctHistory:RenameColumns(Distinct(filteredHistory,ArchivedOn),"Result","ArchivedOn"),
 sortedDistinctArchivedOn:SortByColumns(distinctHistory,"ArchivedOn",Descending)
 }
);

 

With the above, the local variable 'sortedDistinctArchivedOn' does not get populated correctly (is blank).

 

EDITED/ADDED comments for additional clarifications:

I thought about the combined "UpdateContext" function running concurrently when used in that format, BUT I tested it out several times before posting the question, and in the combined "UpdateContext" format, the second variable 'distinctHistory', which is dependent on the first variable 'filteredHistory' DOES get set correctly every time (which led me to believe that it was not running concurrently), and it was only the last variable 'sortedDistinctArchivedOn' that did not get set correctly with each test.

 

Furthermore, I can't recall from which Microsoft documents I read this, but according to MS, Power Apps executes functions/commands in a linear fashion (even when written in combined format), and the only exception where concurrency is used is in using the "Concurrent" function.

 

However, if I code the same logic using multiple "UpdateContext" functions as shown below, then the local variable 'sortedDistinctArchivedOn' is populated correctly with the sorted distinct dates.

 

UpdateContext({filteredHistory:Filter(ResourcesHistory,ResourceID=currentResource.ResourceID).ArchivedOn});
UpdateContext({distinctHistory:RenameColumns(Distinct(filteredHistory,ArchivedOn),"Result","ArchivedOn")});
UpdateContext({sortedDistinctArchivedOn:SortByColumns(distinctHistory,"ArchivedOn",Descending)});

 

 

Does anyone know the reason why or am I doing something wrong?

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    154,494 Most Valuable Professional on at

    Hi @emrrken ,

    That is because that structure runs the elements concurrently, meaning they cannot be dependent on another element - you can do this

    UpdateContext({filteredHistory:Filter(ResourcesHistory,ResourceID=currentResource.ResourceID).ArchivedOn});
    UpdateContext({distinctHistory:RenameColumns(Distinct(filteredHistory,ArchivedOn),"Result","ArchivedOn"});
    UpdateContext({sortedDistinctArchivedOn:SortByColumns(distinctHistory,"ArchivedOn",Descending})

    or this

    With(
     {
     wHistory:
     Filter(
     ResourcesHistory,
     ResourceID = currentResource.ResourceID
     ).ArchivedOn
     },
     With(
     {
     wDistinct:
     RenameColumns(
     Distinct(
     wHistory,
     ArchivedOn
     ),
     "Result",
     "ArchivedOn"
     )
     },
     UpdateContext(
     {	
     sortedDistinctArchivedOn:
     SortByColumns(
     wDistinct,
     "ArchivedOn",
     Descending
     )
     }
     )
     )
    );

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • Verified answer
    emrrken Profile Picture
    9 on at

    @WarrenBelz I should have clarified this in my initial post -- I actually also thought about the combined "UpdateContext" function running concurrently when used in that format, BUT I tested it out several times before posting the question, and in the combined "UpdateContext" format, the second variable 'distinctHistory', which is dependent on the first variable 'filteredHistory' DOES get set correctly every time (which led me to believe that it was not running concurrently), and it was only the last variable 'sortedDistinctArchivedOn' that did not get set correctly with each test.

     

    Furthermore, I can't recall from which Microsoft documents I read this, but according to MS, Power Apps executes functions/commands in a linear fashion (even when written in combined format), and the only exception where concurrency is used is in using the "Concurrent" function.

     

    Based on the observed behavior, I have arrived at the same conclusion you did, is that in the combined "UpdateContext" format, Power Apps is setting the variables concurrently (despite results).  So linear dependency setting of context variables using the combined "UpdateContext" format is not guaranteed to work consistently, so if the context variables being set are dependent upon each other linearly, then you need to separate them individually with "UpdateContext" function according to your logic requirements.

  • WarrenBelz Profile Picture
    154,494 Most Valuable Professional on at

    Thanks @emrrken ,

    So this is solved now?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 549 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 225 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 224

Last 30 days Overall leaderboard