Power Automate Tip: Reduce loop to improve performace


If you are creating very complex flows using Microsoft PowerAutomate which contains loops (Apply To Each connector), you must have noticed that performance degrades sharply. 

I had a loop of 120 items with some complex business logic, which was taking around 40 mins to execute the complete flow. But after I have removed the loops and reduced the number of variables now flow gets completed in less than 8 mins. So you can imagine the performance if your flow is going to be executed on a very large dataset.

To improve the performance of the flow, it's necessary to reduce the loop count and to do that I count on the 2 best functions from Power Automate.

To explain the below functions, I will take a scenario where there are below fields 

  • Title
  • City
  • State

#1: Select

You can make use of the Select function to create a collection/array of single-valued or complex objects, even without looping each item.

Case 1: Suppose I want to collect all the cities from all the records, then I can simply make use of this function and can get an array of all the cities

 As you can see in the below image, on the LHS I have added only the City value in Map field, and I got array as an output 

Case 2: Now, since my data in SharePoint does not have the country, I am aware that all data is going to be of India only, but still due for some reason I need the country also along with each row. So in this case I will make use of the map and will map all the properties I require in my array.

As you can see in the output below that I have a new property "Country" with a fixed value of India. Similarly, you can also manipulate the data and then create an array.

#2: Filter

Now if we want to have a filtered collection, then this is very helpful. Taking the above example if I need the records that are filtered based on City say "Agra".

You can see in the image below that it is very convenient to get all the filtered records in a collection, which will reduce the loop

The only drawback here is that you cannot have multiple filter criteria.

#3. Parse JSON

This function does not help in reducing the loop or increasing the performance, but if you are not good at writing the expressions, then this can be of help as you can parse the outputs of "Select" and "Filter" and then you can easily use the properties in your related action connectors

I will be writing another article to explain how we can write the expressions so that it becomes easy when you are working on very large and complex workflows. Hoping this article will help you in improving the performance of the flow, do comment and let me know if you have any queries.

Happy Automating..!!
#PowerAutomate #SharePointWidgets #Microsoft


Popular posts from this blog

Rename Folder using Microsoft Flow / Power Automate in a Document Library in SharePoint Online

How to check for empty for null and empty Values in Power Automate?

How to resolve certificate issue in SharePoint Framework Solution