Power Automate Apply To Each Loops 20X Faster

Power Automate Apply To Each Loops 20X Faster

Power Automate Apply To Each Loops 20X Faster

The Power AutomateApply to Each‘ loop tends to operate at a reduced pace because it processes actions in a sequential manner. By leveraging parallelism, we can enhance the efficiency of the ‘Apply to Each‘ feature, allowing several threads to operate concurrently. Such parallel processing can boost a flow’s speed, potentially cutting down its completion time by over 20 times. In this piece, I’ll guide you on how to accelerate the ‘Apply to Each‘ action in Power Automate.

Introduction: The Past Due Invoices Flow

A plumbing firm utilizes Power Automate to determine if an invoice is overdue and subsequently modifies its status. To enhance processing speed, the flow updates invoices simultaneously rather than one after the other.

Power Automate flowchart showing simultaneous updates of overdue invoices for a plumbing firm

Setup The SharePoint List

“Set up a new SharePoint List named ‘Company Bills‘ with these columns:

  • BillID (number)
  • SupplierName (single-line text)
  • BillTotal (number)
  • OverdueStatus (yes/no)

Enter the following entries into the ‘Company Bills’ list:

BillIDSupplierNameBillTotalOverdueStatus
1001Ali Shahzad105No
1002Abdullah350No
1003Ahmad Raza240No
1004Muadssar335No

Note: I’ve changed certain terminologies (e.g., “Invoices” to “Bills“, and “VendorName” to “SupplierName“) to give it a different feel while retaining the context. Adjust as needed.

The SharePoint list should appear as follows once configured.

Configured SharePoint list for Power Automate Parallel Processing workflow

Run Apply To Each Loops Actions One-At-A-Time

We aim to develop a process that retrieves all entries from the Company Invoices SharePoint list and sets the IsPastDue column to “Yes.” Initially, our flow will process each item sequentially. We will then optimize it to process multiple items concurrently.

Proceed to design the specified process in Power Automate. During the Update Item stage, adjust the IsPastDue column to “Yes” in the ‘Change Past Due To Yes’ action.

Examine the flow to determine its speed. During this examination, the flow finished in 9 seconds.

Power Automate flow completing in 9 seconds, showcasing parallel processing efficiency

Improve Apply To Each Speed 20X With Parallelism

The ‘Apply To Each’ action is currently lagging in our workflow. We can enhance its speed significantly by utilizing parallel processing. This technique lets us run multiple threads simultaneously. To activate parallel processing, go to the ‘Apply To Each’ action settings.

Enabling parallel processing in Power Automate to speed up 'Apply to Each' action.

Next, enable Concurrency control. By default, it allows 20 simultaneous threads. Before increasing this number, it’s advisable to review the throttling limits of the Power Automate SharePoint connector. Overloading with too many concurrent API calls might actually reduce the flow’s speed.

Once you’ve set the desired parallelism level, click ‘Done‘.

Check the flow’s speed to gauge its efficiency. It now finishes in just 2 seconds, down from the previous 9 seconds. What a remarkable enhancement!

Power Automate flow finishing in 2 seconds, showcasing efficient parallel task processing

Problems With Variables While Using Parallelism In Loops

Let’s examine a different situation to grasp the constraints of parallel processing and strategies to address them. In this process, we aim to increase the ‘InvoiceAmount‘ column for every company invoice by 10, as a penalty for missed payments.

We’ve introduced an ‘Initialize Variable’ action at the beginning of the flow and assigned a value of 0 to varUpdatedAmount. Within the ‘apply to each’ loop, we incorporated a ‘Set Variable’ action using the provided code.

				
					add(items('Apply_to_each')?['InvoiceAmount'], 10)

				
			

When initiating a ‘Set variable’ step within an ‘apply to each’ loop in Power Automate, we receive a cautionary prompt. Using variables in a loop with parallelism active is not recommended. This poses a risk, as simultaneous threads could alter our variable, leading to inaccurate outcomes in the ‘Update Item’ action.

Power Automate = Initializing and Setting Variables with Parallel Processing Warning

Replace Set Variable In Apply To Each Action With Compose

How can we address this issue? It’s necessary to utilize variables inside the ‘Apply to Each’ function. Luckily, there’s an alternative method.

Eliminate the ‘Initialize Variable’ at the beginning of the flow. Subsequently, within the ‘Apply to Each’ loop, substitute the ‘Set Variable’ action with a ‘Compose’ action.

The “Compose” action delivers its outcome in a text format. Thus, in the “Update Item” action’s InvoiceAmount field, we need to draft a flow expression to convert the type to a float, which represents a decimal number.

				
					float(outputs('Compose'))
				
			

The flow now operates without displaying any warnings and achieves the expected outcome. Please test the flow to ensure its continued functionality.

Some Relevant Insights:

  1. What It Is: Power Automate Parallel Processing involves running multiple threads simultaneously to enhance the speed of ‘Apply to Each‘ loops in workflows.
  2. Benefit: This method can accelerate flow completion times by over 20 times compared to sequential processing.
  3. Use Case: Particularly useful in scenarios like updating multiple SharePoint list items concurrently.
  4. Limitation: Caution is advised when using variables in parallel processing due to the risk of inconsistent outcomes.
  5. Solution: Using the ‘Compose‘ action instead of ‘Set Variable‘ within the loop for safer and more efficient operations.

Conclusion:

Implementing parallel processing in Power Automate can be a game-changer for businesses looking to streamline their workflows. It offers remarkable speed improvements, particularly in handling multiple tasks simultaneously, such as updating SharePoint lists. However, it’s important to be mindful of potential pitfalls like variable inconsistencies and to adapt strategies, such as using the ‘Compose’ action, for optimal results. Embracing this approach not only enhances efficiency but also leverages the full potential of Power Automate in managing and automating complex workflows.

If you want to learn more about the Power Apps, feel free to explore our other informative articles and tutorials.

Have additional inquiries? Our team is here to assist. Please don’t hesitate to reach out!

About The Author