The more I work with Microsoft Power Automate, the more I appreciate its ability to handle complex data processing tasks. However, one topic that consistently trips up both new and experienced developers is how variables behave inside Apply to Each Loops, especially when parallelism is enabled. If you have ever had a flow that worked perfectly in testing but produced inconsistent or missing data in production, this might be the culprit.
In this article, we will explore how variables interact with Apply to Each Loops, why enabling parallelism can break your flow, and what alternatives you can use to get consistent results.
How Variables Work in Microsoft Power Automate
Variables are initialized at the flow level using the Initialize Variable action and can be modified throughout the flow using actions like Set Variable, Increment Variable, or Append to Array Variable.
The key thing to understand is that variables in Microsoft Power Automate are global to the flow instance. When you initialize a variable, it exists as a single value that any action in the flow can read or modify. There is no concept of local scope or thread-local storage.
This works perfectly fine in sequential execution where one action completes before the next one starts, but it becomes problematic when multiple operations try to access or modify the same variable simultaneously.
The Apply to Each Loop
The Apply to Each action allows you to iterate over an array and perform actions on each item. By default, Apply to Each loops process items sequentially, one at a time, in order. In this mode, using variables inside the loop works exactly as you would expect.
The loop picks up Item 1, the variable gets updated, the loop moves to Item 2, and so on. This sequential processing is predictable and safe for variable manipulation, however sequential processing can be slow when working with large arrays. If each iteration makes an API call that takes two seconds, processing 100 items will take over three minutes.
Degrees of Parallelism: The Double-Edged Sword
Microsoft Power Automate allows you to enable concurrency control on Apply to Each Loops through the Settings menu. The Degree of Parallelism setting (ranging from 1 to 50) determines how many iterations can run simultaneously.
To access this setting, click on the three dots in the upper right corner of your Apply to Each action, select Settings, and toggle Concurrency Control to On. You can then specify the degree of parallelism using the slider or by typing a number directly.
Enabling parallelism can dramatically improve performance. A loop that took three minutes to process 100 API calls sequentially might complete in under 15 seconds with parallelism set to 20. However, this is where variables become a serious problem.
Why Variables Break with Parallelism in Power Automate
When parallelism is enabled, multiple iterations of your loop execute at the same time. If those iterations are all trying to read and write to the same variable, you get what is called a race condition. The iterations are racing each other to access the variable, and the outcome depends on timing that you cannot control.
Consider this scenario with an Append to Array Variable action inside a parallel loop:
- Iteration 1 reads the array variable (currently empty)
- Iteration 2 reads the array variable (still empty, Iteration 1 has not written yet)
- Iteration 1 appends "Value A" to the array
- Iteration 2 appends "Value B" to the array (but it started with empty, so the array now only contains "Value B")
Instead of an array containing both values, "Value A" is completely lost. The exact outcome varies depending on timing, which means you might get different results every time the flow runs.
I have seen production flows where an array that should have contained 50 items ended up with only 12, with no errors reported anywhere in the run history. The flow appeared to complete successfully, but the data was silently corrupted.
Solutions and Workarounds
The simplest and most reliable solution is to keep parallelism disabled when your loop contains variable operations. Set the Degree of Parallelism to 1, which is the default. If your loop does not process a large number of items or if the actions inside are quick, sequential processing is perfectly acceptable. This is my recommendation when the loop contains variable manipulation and performance is not critical.
If you need parallelism for performance, use a Compose action inside the Apply to Each to output the item's result instead of appending to a variable. Microsoft Power Automate automatically collects the outputs from actions inside Apply to Each Loops into an array, which you can access after the loop completes using an expression like outputs ('Compose'). This avoids the race condition because you are not modifying a shared variable.
Power Automate Best Practices
- Never use Set Variable, Append to Array Variable, or Increment Variable inside a parallel Apply to Each Loop.
- If you must use variables inside Apply to Each, disable parallelism by setting the Degree of Parallelism to 1.
- Use Compose outputs as an alternative to array variables when parallelism is required.
- Test with realistic data volumes. A flow that works with 5 test records might fail with 500 due to timing differences.
Understanding why variables and parallelism do not mix gives you the knowledge to build flows that are both fast and reliable.

Working with New Dynamic
New Dynamic is a Microsoft Solutions Partner focused on the Dynamics 365 Customer Engagement and Power Platforms. Our team of dedicated professionals strives to provide first-class experiences incorporating integrity, teamwork, and a relentless commitment to our client’s success.
Contact Us today to transform your sales productivity and customer buying experiences.