Understand Concurrency Control In Apply To Each Loop In Power Automate

Introduction

In Power Automate, we must consider performance related things while working on apply to each action. During most of the scenarios concurrency control option present in apply to each action will come for rescue to process records faster pace with the usage of 50 parallel threads rather than 1 by 1 to process all the collection of records those are present in apply to each. As an example on list action on contacts that is present in Dataverse along with apply to each loop was used to explain this behavior.

Step 1

Login to the required Power Apps environment using URL make.powerapps.com by providing username and password and click on Flows on the left-hand side as shown in the below figure.

Understand Concurrency Control In Apply To Each Loop In Power Automate

Step 2

After Step 1, Click on New Flow and select instant cloud flow and provide the trigger as Manually trigger a flow and click on Create as shown in the below figure.

Understand Concurrency Control In Apply To Each Loop In Power Automate

Step 3

After Step 2, name the flow as Understand Concurrency control in apply to each loop and take a list rows action in Dataverse and select contacts as table name and write the fetchxml query as below,

<fetch top="50" >
    <entity name="contact">
    </entity>
</fetch>

as shown in the below figure.

Understand Concurrency Control In Apply To Each Loop In Power Automate

Step 4

After Step 3, take apply to each action create HTML table – For each record from list as shown in the below figure.

Understand Concurrency Control In Apply To Each Loop In Power Automate

Step 5

After Step 4, save and run the flow and observe the time of 3 seconds for execution of apply to each loop as shown in the below figure.

Understand Concurrency Control In Apply To Each Loop In Power Automate

Step 6

After Step 5, now select Apply to each step and click on 3 dots and click on settings as shown in the below figure.

Understand Concurrency Control In Apply To Each Loop In Power Automate

Step 7

After Step 6, enable Concurrency control to On and provide Degree of Parallelism to 50 and click on Done as shown in the below figure.

Understand Concurrency Control In Apply To Each Loop In Power Automate

Step 8

After Step 7, now save and run the flow and observe the execution time of Apply to each loop gets reduced to 2seconds as shown in the below figure.

Understand Concurrency Control In Apply To Each Loop In Power Automate

Note

  1. Make sure to save the flow whenever you try expressions.
  2. Here in the example considered fetching data from list records on Dataverse, in other scenarios like fetching data from other resources like SharePoint and traversing the items inside loop one can observe significant performance improvement.
  3. Don’t use this concurrency control, if at all any logic was returned to process items in a specific order like updating a variable then enabling concurrency might not be a good idea because the loops are running parallelly you will get inaccurate results in those scenarios, ensure that concurrency control was not used.
  4. I have concentrated only to explain concurrency control in apply to each loop only not on creating HTML table.

Conclusion

In this way we can use concurrency control in power automate to decrease the execution time of applying to each loop.


Similar Articles