web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Does ForAll() evaluate...
Power Apps
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 1,811 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

 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at

    @johnjohnPter ,

    If you have Collect inside ForAll, it will execute sequentially as will a Patch (it will do an individual Patch or Collect action for each iteration). If you have ForAll inside Patch, you will have a bulk Patch (one action) with the Table created by ForAll.

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • johnjohnPter Profile Picture
    1,811 Super User 2024 Season 1 on at

    @WarrenBelz so my code i have where i am building collections and RemoveIF() them, should be robust and the result i get is not by chance??

     

  • johnjohnPter Profile Picture
    1,811 Super User 2024 Season 1 on at

    @Pstork1 any advice on @WarrenBelz reply? Thanks

  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at

    @johnjohnPter ,

    I did not look at that part, however if you want to clear a collection

    Clear(colRelatedPlannerTasks);
    Clear(colRelatedPlanners);
  • johnjohnPter Profile Picture
    1,811 Super User 2024 Season 1 on at

    @WarrenBelz i can not use Clear() collection inside ForAll(),, but i can use RemoveIF()

  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    As I've already said in another thread, and as the documentation describes a ForAll() does NOT apply the formula sequentially by default. You can force it to do it sequentially if you add a Sequence field.  otherwise "The ForAll function evaluates a formula for all the records in a table. " It does not guarantee that it will do each record in order.

  • rzuber Profile Picture
    545 Moderator on at

    @johnjohnPter - What @Pstork1 is saying is the same reason why you can't Remove()/RemoveIf() a record from the datasource that is the focus of the ForAll().

     

    For example, you can't do this

    rzuber_0-1718563854666.png

     

    And if you put your mouse over the line with the squigglies under it, Power Apps will tell you:

    rzuber_1-1718563919781.png

  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at

    @johnjohnPter ,

    You do not need to use ForAll with Clear as it clears the entire collection (what I posted replaces what you had). I can also confirm that using Collect inside ForAll in an example I use ((see this blog) collects the data sequentially.

  • johnjohnPter Profile Picture
    1,811 Super User 2024 Season 1 on at

    @Pstork1 but based on my test and the above replies, if we have a Patch inside ForAll() the patch will be executed in sequence, and this what is happening based on my test.

  • johnjohnPter Profile Picture
    1,811 Super User 2024 Season 1 on at

    @rzuber not sure why you are getting this error, but in my case i am able to do 2 RemoveIf()

     

    RemoveIf(colRelatedPlannerTasks,true));
    RemoveIf(colRelatedPlanners,true));

     

    inside 2 ForAll() as shown in my original code... so seems i can do RemoveIf() inside ForAll()

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard