Skip to main content

Fixed: An Action Meant for After the Loop Runs Inside It in Power Automate

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

I added a summary to run once, after a loop over 14 rows. In the run, it ran at the start of every row, and the first time it said Imported 0: none. Skipped 0: none. I'd used the + just under the loop's header, which adds the loop's first step. The + after the loop's box adds the step after it.

What I Was Doing​

I was building Import Old Overtime Timesheet, a flow of the Overtime Timesheet app that imports the rows of an old Excel timesheet. An Apply to each named For each old row handles one row at a time and adds a line to one of three array variables: rows imported, rows skipped, and rows whose hours differ from the workbook (How to Add Items to an Array Variable in Power Automate).

After the loop, a Compose named Import summary was to turn the three lists into one text (How to Use the Compose Action in Power Automate). In the new designer, I selected the + right below the loop's header and added the Compose there.

What I Expected​

One summary at the end of the run, listing all 14 rows: the imported ones, the skipped ones with their reasons, and the hours that differ.

What I Got​

The run showed Import summary inside the loop, once for each row. In the first iteration, nothing had been imported or skipped yet:

The Outputs of Import summary in the first iteration of the loop: Imported 0: none. Skipped 0: none. Hours that differ from the workbook: none.

The rest of the run had worked: the rows were imported. Only the summary was in the wrong place.

What I Checked​

Where the action was. Paging through the loop's iterations, Import summary was the first step inside each one, before the steps for the row.

Its Code view. It had no runAfter. Inside a loop, the first action has none: it runs when the iteration starts. An action after the loop has the loop in its runAfter.

The designer's labels. Each + on the canvas has a label, the name a screen reader reads out. The one under the loop's header is Insert a new action between For each old row and Finish date, Finish date being the loop's first step at the time. The one under the loop's box is Insert a new action after For each old row.

Microsoft's documentation. The Power Automate licensing FAQ puts it plainly: Actions inside a loop (Apply to Each, Do Until) run once per iteration.

Why It Happens​

The loop's box contains its steps. The + under its header is the start of that box, so an action added there becomes the loop's first step and runs for every item. The + below the box is the next step of the flow.

The Fix​

  1. Delete the misplaced action. Right-click Import summary on the canvas, select Delete, and confirm with OK. Copy its expression first if you want to paste it again.

  2. Add it after the loop. Select the + below the loop's box, the one labelled Insert a new action after For each old row, then Add an action, and add the Compose again.

  3. Check its Code view. runAfter now names the loop:

    The Code view of Import summary: type Compose, the concat of Imported, Skipped and Hours that differ from the workbook, and runAfter For_each_old_row Succeeded

  4. Save and publish the flow (How to Save a Draft and Publish a Flow in Power Automate).

After the Fix​

On the canvas, with the loop collapsed, Import summary is below the loop's box:

The top level of the flow: Manually trigger a flow, List the old rows, Get the departments, three Initialize variable actions, the For each old row loop collapsed with 11 Actions, and Import summary after it

The next run had one summary, after the last row, with every row in it. This run came after the rows had been imported, so each one was already imported:

The Outputs of Import summary after the loop, beginning Imported 0: none. Skipped 14: Aisha Khan, 02/10/2026: already imported; Ben Harris, 04/10/2026: already imported, and so on through all 14 rows

Common Mistakes​

MistakeWhat happensDo this instead
The + under the loop's headerThe action becomes the loop's first stepThe + below the loop's box
Not checking where a new action wentIt can be inside the loop without looking out of placeCheck runAfter in Code view
Reading the summary's first iteration as the resultIt ran before any rowLook for one run of the summary, after the loop

Troubleshooting​

SymptomLikely causeFix
A summary shows 0 or none while the loop workedIt runs inside the loopMove it after the loop
An action runs once per item instead of onceIt's inside the loopCheck where it sits in the loop's iterations
No runAfter in an action's Code viewIt's the first step of the flow or of a containerExpected for a loop's first step

FAQ​

Why didn't the designer warn me?​

Nothing was wrong as far as the designer could tell: a Compose is a valid first step for a loop, and Flow checker found no errors or warnings.

Do variables keep their values after the loop?​

Yes. Variables live for the whole run, so a step after the loop sees everything the loop added (How to Use Variables in Power Automate).

Conclusion​

An action meant for after an Apply to each ran inside it because I added it with the + under the loop's header. Adding it with the + below the loop's box, labelled Insert a new action after the loop, made it run once, at the end, with the loop in its runAfter.

Additional Resources​