I have a problem understanding how the ForAll() works internally, based on the documentation it will execute all the formulas at once, but based on my test it will do this based on a sequence one by one. for example i have this formula which do these steps:-
ClearCollect(colTeamSitesItem,Filter('Team Sites',1=1));
ClearCollect(colAllGroups,Office365Groups.ListGroups().value);
ForAll(colAllGroups As group,
ForAll(colTeamSitesItem As i2,
If(Lower(group.displayName)=Lower(i2.'Team Site Name'),
Collect(colRelatedGroupsIds,group.id))));
ForAll(colRelatedGroupsIds As group,
Collect(colRelatedPlanners,
Planner.ListGroupPlans(group.Value).value);
ForAll(colRelatedPlanners As planner,
Collect(colRelatedPlannerTasks,
Planner.ListTasksV3(planner.id,group.Value).value);
ForAll(colRelatedPlannerTasks As task,
ForAll(task._assignments As taskAssignment,
Patch(finalResult,Defaults(finalResult),
{
PlanTitle:planner.title,
AssignedToUserId:taskAssignment.userId,
Status:task.percentComplete,
TaskTitle:task.title,
DueDate:task.dueDateTime
})
));
RemoveIf(colRelatedPlannerTasks,true));
RemoveIf(colRelatedPlanners,true));
1) Get the Office 365 groups from a sharepoint list
2) Get All the Office 365 groups from AD
3) check if the AD group is define inside the sharepoint group and build the colRelatedGroupsIds
4) iterate over the colRelatedGroupsIds >> and for each group get the group plans + iterate over the Plan Tasks
5) after iterating over each plan + each group i Clear the related collection, to avoid duplicate and wrong Plan Tasks.
now my above code is working well.. but it could not work well, unless the ForAll() execute the formulas in a sequence and not all at once.. but based on my reading is that ForAll() does not execute the formulas in a sequence but rather all at once.. so can anyone advice how ForAll() works internally?
Thanks
As mentioned earlier. ForAll() in PowerApps executes formulas sequentially, despite some ambiguities in the documentation. The idea of ForAll() is the same concept for apply_to_each or Do_until loop on PowerAutomate. This sequential behavior ensures that each iteration completes before the next starts, which is crucial for nested loops and dependent operations.
While it's always possible that Microsoft could update how ForAll() works, there is no specific indication that this behavior will change soon. However, to future-proof your application, consider the following:
Stay Informed:
Best Practices:
Alternative Approaches:
While ForAll() currently executes sequentially, it’s essential to design your app with flexibility to adapt to any future changes. Stay updated with PowerApps developments and consider alternative methods for critical sequential processes.
By following these guidelines, you can ensure your app remains functional and efficient, even if the behavior of ForAll() changes in the future.
Did you set the Loops in the Flow to run in parallel? Did you avoid using Variables inside the loop? That's hos you improve the performance of the flow to get it to run faster. Other than that or using a recurrence flow to do it at given times and store the result to another list where you can pick up the results I have no other suggestions.
@Pstork1 i tired to do this inside power automate, and call the flow inside power apps, but it did not work, as the flow will take more than 2 minutes.. so the power apps will raise an error
According to the documentation you would do it using a Sequence() function, but I'm not sure how that would work. As I mentioned earlier if you need it to run sequentially I would call a Power Automate flow. Power Automate is procedural by definition while Power Apps is declarative.
@Pstork1 ok thanks for the additional info, so how i can force all the ForAll() to run in sequential order?
ClearCollect(colTeamSitesItem,Filter('Team Sites',1=1));
ClearCollect(colAllGroups,Office365Groups.ListGroups().value);
ForAll(colAllGroups As group,
ForAll(colTeamSitesItem As i2,
If(Lower(group.displayName)=Lower(i2.'Team Site Name'),
Collect(colRelatedGroupsIds,group.id))));
ForAll(colRelatedGroupsIds As group,
Collect(colRelatedPlanners,
Planner.ListGroupPlans(group.Value).value);
ForAll(colRelatedPlanners As planner,
Collect(colRelatedPlannerTasks,
Planner.ListTasksV3(planner.id,group.Value).value);
ForAll(colRelatedPlannerTasks As task,
ForAll(task._assignments As taskAssignment,
Patch(finalResult,Defaults(finalResult),
{
PlanTitle:planner.title,
AssignedToUserId:taskAssignment.userId,
Status:task.percentComplete,
TaskTitle:task.title,
DueDate:task.dueDateTime
})
));
RemoveIf(colRelatedPlannerTasks,true));
RemoveIf(colRelatedPlanners,true));
Thanks
I agree that in practice the results will normally appear to run in sequence. But as I've pointed out you can't depend on it to do that. I have seen instances where applying the expression to different records takes more or less time and the result is therefore not in sequential order.
As I said, usually it will appear to work in sequence if the data is all similar because applying the formula will take the same amount of time for each record. But there is no guarantee of that. I've seen that in experimentation and that is the way it is described in the documentation. You can't depend on it working in sequence.
@johnjohnPter I don't think this behavior will change in the future. It is necessary behavior for reusable code. But only the Power Apps dev-team knows for sure.
@rzuber Yes currently the ForAll() will execute the formulas in sequential order, this also based on my test over many applications and using different formulas.. but can this behavior get changed in the future? as seems the documentation is not clear enough for us to be sure about how ForAll() works internally especially on the sequence of execution ; sequential or in parallel? what do you think?
@Kellboy2243 thanks for the very helpful reply.. so this means that currently ForAll() execute the formulas in sequence, but as you mentioned this is not what mentioned in the documentation or the documentation is not clear (i am not sure which one actually applies to the documentation)... so can i say that this behavior of the sequential execution for the ForAll() might get changed at some point in the future?
MS.Ragavendar
32
Rajkumar_M
16
Super User 2025 Season 1
mmbr1606
16
Super User 2025 Season 1