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?