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?

Solution Sage
Solution Sage


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

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

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.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (1,807)