web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Slow Apply to Each loop
Power Automate
Unanswered

Slow Apply to Each loop

(0) ShareShare
ReportReport
Posted on by 6

Hello Everyone,

I need some advice on improving the performance of a flow I've created in Power Platform. This flow is designed to fetch data from a Dataverse table and parsed JSON data.

Within this flow, I'm using an "Apply to Each" loop, in which I utilize a "Filter Array" operation to determine whether the current item in the loop (which corresponds to a Unique ID from the JSON) already exists in the Dataverse table. If it does, the flow takes no action, but if it doesn't, it adds a new row.

The section of the flow that is particularly problematic, leading to extended delays, is the portion responsible for executing the "Filter Array" operation and adding new rows to the Dataverse table. These steps are noticeably impacting the overall performance of the flow.

Within the "Filter Array" operation, I've experimented with two approaches: one using a direct link to the Dataverse table, as depicted in the screenshot below, and the other involving a combination of "Select" and "Union" composes to optimize the process by reducing the need to check both tables within the loop. Unfortunately, neither of these strategies had a significant impact on the runtime of the flow.

The issue I'm facing is that the execution time of this flow varies significantly. Some runs complete in less than 10 minutes, while others take much longer, with the longest run so far lasting 26 hours, even though the data being processed remains the same.

I'm seeking advice on how to optimize the flow for consistent and faster performance or if there is a more efficient approach to achieve the same outcome. Your insights and suggestions would be greatly appreciated.

Thank you in advance!

 

kieranbirkett95_0-1698693525674.png

kieranbirkett95_2-1698693561755.png

 

kieranbirkett95_1-1698693543934.png

 

Categories:
I have the same question (0)
  • CFernandes Profile Picture
    8,402 Most Valuable Professional on at

    Hey @kieranbirkett95 

     

    Can you try to set up concurrency for the apply to each loop?

     

    CFernandes_1-1698696273991.png

     

     

    CFernandes_0-1698696240803.png

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

     

    P.S. take a look at my blog here and like & subscribe to my YouTube Channel thanks.

     

  • kieranbirkett95 Profile Picture
    6 on at

    I have tried this solution and set it to 50 and still resulted in the same long timescales. As I mentioned above I could be processing say 1500 things within the apply to each loop and on one 1 run it can take 10 minutes and the next run it could be 9 hours.

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    The most efficient approach would be to filter out the values that need to be added, then just loop through those items. This will avoid the need for a Condition inside the Apply to each as you are only looping over items that need to be added.

     

    For this example I have a Dataverse table and an Excel Table (would be the same as your CSV data since you already have it in JSON format).

     

    Below is the Dataverse Table I'm using for this example.

    grantjenkins_0-1698716229106.png

     

    Below is the Excel Table I'm using for this example. Note that it has two rows that don't exist in the Dataverse Table.

    grantjenkins_1-1698716278980.png

     

     

    See full flow below. I'll go into each of the actions.

    grantjenkins_2-1698716337571.png

     

    List rows retrieves the data from Dataverse.

    grantjenkins_3-1698716454272.png

     

    List rows present in a table retrieves the data from the Excel Table.

    grantjenkins_4-1698716475200.png

     

    Select extracts out the Unique IDs from the Dataverse Table into a simple array.

    grantjenkins_5-1698716533084.png

     

    Filter array retrieves items from our Excel Table that are not in the Dataverse Table. Do to this, it checks to see if the list of Unique IDs from Dataverse do not contain the current Unique ID from the Excel Table.

    grantjenkins_6-1698716634713.png

     

    Apply to each iterates over the items in the Filter array (only the items that don't exist in Dataverse).

    grantjenkins_7-1698716696815.png

     

    Add a new row adds the rows using the data from Filter array. Below are the expressions used to get the data for Name and Unique ID.

    //Name
    item()?['Name']
    
    //Unique ID
    item()?['Unique ID']

    grantjenkins_9-1698716884244.png

     

    After running my flow we would have the two additional rows added.

     

    grantjenkins_11-1698717075579.png

     

    IN ADDITION:

    I noticed that you were using a loop to extract your CSV data. We should be able to extract the CSV data into JSON format without a loop which will also help to speed up your flow. Would you be able to show what your raw CSV output is (column headers and a couple of rows of data)? Also, do any of the values contain commas with the actual text?

  • kieranbirkett95 Profile Picture
    6 on at

    Thank you is all I can say!

    I just re-ran an iteration from last night that took 6 hours and it completed in under 24 seconds.

    Regarding the CSV section, this only takes an average of 15 seconds inside the loop to convert the CSV into JSON format.

    Certain values within the rows do contain commas within the actual text yes, I've uploaded a dummy version of the data for you 🙂

    split(outputs('Get_file_content_using_path')?['body'], decodeUriComponent('%0D%0A'))

    kieranbirkett95_0-1698739668877.png


    split(item(), '",')

    kieranbirkett95_1-1698739688608.png

     

    kieranbirkett95_2-1698739705032.png

     

    kieranbirkett95_3-1698739722604.png

     

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Glad to hear it's working and improved the duration 🙂

     

    Given that your CSV has multiple columns that could have commas in the values, and it's only taking ~15 seconds to complete, I'd just leave it how you currently have it.

     

    The other option would be to look at using Office Scripts to extract the data into JSON for you.

  • CU16120934-0 Profile Picture
    2 on at
    @grantjenkins Hello, i have experienced the same issue, but my apply to each step does not related to excel/ csv. can you review and share your thoughts here? 
     
    I have a flow that connects to Excel file in SharePoint, checks if it exists or not, (if yes - delete it and re-create it, if no- create it), list rows in the table, and connect to power bi paginated report (with parameter) to Send dynamic email to each email that match has found (between the excel table, to the parameter in the paginated report). as you can see, the Apply to each takes forever. it actually takes approx 5 minutes to each row and failed after 8-9 rows due to hitting the action limit. can you advise what additional options i have here (instead of this loop). many thanks!
     
     
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard