Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 5/D2CxMX8entv6gfwh2Vzs
Power Apps - Building Power Apps
Unanswered

Does ForAll() evaluate the iteration all at once or based on a sequence

Like (0) ShareShare
ReportReport
Posted on 16 Jun 2024 08:14:52 by 1,546 Super User 2024 Season 1

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

 

  • Kellboy2243 Profile Picture
    51 on 29 Jun 2024 at 23:58:20
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    Hi @johnjohnPter 

     

    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.

     

    Potential Changes:

    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:

    Steps you can take:

    1. Stay Informed:

      • Regularly check PowerApps updates and release notes for any changes to ForAll() behavior.
      • Follow the PowerApps community and official forums for announcements.
    2. Best Practices:

      • Decouple Dependent Operations: Minimize dependencies between iterations where possible.
      • Error Handling: Implement robust error handling to manage unexpected behavior changes.
    3. Alternative Approaches:

      • If sequential execution is critical, consider using ForAll() within a context that ensures sequential execution, or use Power Automate for complex workflows.

    Additional Tips:

    • Testing and Monitoring: Continuously test your app after updates to ensure expected behavior.
    • Modular Design: Design your app in modular components to easily adapt to any changes in ForAll() behavior.

    Final Advice:

    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.

  • Pstork1 Profile Picture
    66,106 Most Valuable Professional on 24 Jun 2024 at 17:50:48
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    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.

  • johnjohnPter Profile Picture
    1,546 Super User 2024 Season 1 on 24 Jun 2024 at 17:05:25
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    @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

  • Pstork1 Profile Picture
    66,106 Most Valuable Professional on 17 Jun 2024 at 12:13:28
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    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.

  • johnjohnPter Profile Picture
    1,546 Super User 2024 Season 1 on 17 Jun 2024 at 08:15:00
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    @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

  • Pstork1 Profile Picture
    66,106 Most Valuable Professional on 17 Jun 2024 at 03:27:22
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    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.

  • Pstork1 Profile Picture
    66,106 Most Valuable Professional on 17 Jun 2024 at 03:24:53
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    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.

  • rzuber Profile Picture
    545 Super User 2025 Season 1 on 17 Jun 2024 at 01:04:46
    Re: Does ForAll() evaluate the iteration all at once or based on a 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.

  • johnjohnPter Profile Picture
    1,546 Super User 2024 Season 1 on 17 Jun 2024 at 00:42:42
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    @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?

  • johnjohnPter Profile Picture
    1,546 Super User 2024 Season 1 on 17 Jun 2024 at 00:39:56
    Re: Does ForAll() evaluate the iteration all at once or based on a sequence

    @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?

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
MS.Ragavendar Profile Picture

MS.Ragavendar 32

#2
Rajkumar_M Profile Picture

Rajkumar_M 16 Super User 2025 Season 1

#2
mmbr1606 Profile Picture

mmbr1606 16 Super User 2025 Season 1

Overall leaderboard