Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Looping through files multiple times

Flow intentions:

Recurrence once per week

Get all files in folder (currently 22 files)

Loop through each file (each file contains an array of up to 5000 items)

Create a new file with either 150 items or up to the last item if the end of the file is reached



I am seeing that all files are placed in the correct folder with a max of 150 items as I expect. Even after the flow finishes with the 22 files, it continues and starts looping through the first file again. If it would end when I expect it to, it would take roughly 20 hours to complete.











Is there a better way to set this up? Why is it restarting the loop when it finishes with the last file? Can this process be ran in parallel to speed up the amount of time it takes?

Super User
Super User


Your flow is going into continuous loops because of the "Apply to each".


When you use  "Apply to each" action it takes an array as input and loops through each item in the array. If my array has 5 items the loop will run 5 items and like wise.


In your scenario I think the problem is that in the first or second iteration of the loop all the files are getting created, the next iterations are happening because of the number of elements in the array.


To break this you can make use of the terminate action in Power Automate, this will help you in stopping the flow execution 





You can also try creating parallel branches in the flow, but I don't think that would have a major impact considering that the actions are nested in an Apply to Each loop. I would suggest use of Terminate action.


If the information shared helps you please consider giving a thumbs up 👍 and mark solution as resolved

Please follow my website PowerCards for more information related to Power Platform

Helpful resources

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (2,208)