Loop limit exceeded – Flow loop has exceeded the maximum number of allowed iterations.

Loading

Power Automate allows users to create loops using “Apply to Each”, “Do Until”, and “For Each” actions. However, if a loop exceeds the platform’s iteration limit, the flow will fail with a “Loop Limit Exceeded” error.

This guide explains:
Common causes of excessive loop iterations
How to diagnose and fix the issue
Best practices to optimize loops and prevent failures


Step 1: Understanding Loop Limits in Power Automate

Loop TypeMaximum Iterations Allowed
Apply to Each100,000 iterations per flow run
Do Until5,000 iterations per flow run
For Each100,000 iterations per flow run

Power Automate imposes these limits to prevent infinite loops and excessive resource consumption.


Step 2: Diagnosing the “Loop Limit Exceeded” Error

2.1. Check Flow Run History

  1. Open Power Automate (https://make.powerautomate.com).
  2. Go to My Flows → Select the failing flow.
  3. Click Run History and open a failed run.
  4. Locate the loop action (e.g., “Apply to Each”, “Do Until”).
  5. Check how many times the loop ran before failure.

2.2. Identify the Root Cause

The loop might be running excessively due to:
Too many records – The loop is processing an unexpectedly large dataset.
Incorrect exit conditions – The “Do Until” loop never meets its exit criteria.
Inefficient filtering – The flow iterates over unnecessary items.


Step 3: Fixing the “Loop Limit Exceeded” Error

3.1. Reduce the Number of Items Processed

Problem: The loop processes too many items at once.

Solution:

  • Use a “Filter Array” action before the loop to remove unnecessary items.
  • Use pagination for large datasets.

Example: Filtering a SharePoint list before looping:

Filter: Status equals "Pending"  
Only loop through pending items instead of all records

3.2. Optimize “Apply to Each” for Large Datasets

Problem: Processing too many records from SharePoint, Dataverse, or Excel.

Solution:

  • Use “Top Count” to limit results in a Get Items action.
  • Consider using Parallel Processing (see Step 3.5).

3.3. Fix “Do Until” Exit Condition Issues

Problem: The “Do Until” loop never meets its condition, causing an infinite loop.

Solution:

  • Add a counter variable to exit after a set number of iterations.

Example: Preventing an infinite “Do Until” loop

Set counter = 0
Do Until (Status = "Complete" OR counter > 100)
Increment counter by 1

This ensures the loop does not exceed 100 iterations.


3.4. Use Data Chunking Instead of Large Loops

Problem: The flow processes huge datasets in a single loop.

Solution:

  • Instead of processing 100,000 records in one run, split the data into smaller chunks.
  • Use “Skip” and “Top” in queries to process records in batches.

Example: Processing 500 records at a time in SharePoint

Get first 500 records → Process them → Skip 500 → Get next 500 → Repeat

This prevents hitting the 100,000 iteration limit.


3.5. Enable Parallel Processing (For “Apply to Each”)

Problem: The flow takes too long because it processes items one by one.

Solution:

  • Enable concurrent processing in the “Apply to Each” action:
    1. Click the three dots (...) on “Apply to Each”.
    2. Select Settings.
    3. Enable Concurrency Control and set Degree of Parallelism (e.g., 50).

🔹 This allows multiple iterations to run at the same time, reducing execution time.


3.6. Use Expression-Based Filtering to Reduce Loops

Problem: The loop iterates through all items, even when only a few are relevant.

Solution:

  • Use filter expressions before entering the loop.

Example: Query only “Pending” items from SharePoint instead of all records

OData Filter Query: Status eq 'Pending'

This prevents looping over unnecessary data.


3.7. Switch to Alternative Methods (Power Automate Limits Workarounds)

Problem: The loop limit cannot be reduced, but needs to process a large dataset.

Solution:

  • Use Power Automate Desktop for large automation tasks.
  • Use Azure Logic Apps (no hard iteration limits).
  • Break the flow into multiple sub-flows to process data in stages.

Step 4: Preventing Future “Loop Limit Exceeded” Errors

4.1. Always Filter Data Before Processing

  • Use “Filter Query” instead of retrieving all records.
  • Reduce the number of items sent to “Apply to Each”.

4.2. Monitor Flow Run Performance

  • Regularly check Flow Run History for long-running loops.
  • Set alerts for excessive execution times.

4.3. Use Batch Processing for Large Data Sets

  • Instead of looping through 100,000 records in one run, split data into batches of 1,000.

4.4. Add Exit Conditions to Loops

  • For “Do Until” loops, always include a backup counter to prevent infinite loops.

Step 5: Setting Up Alerts for Loop Issues

To detect excessive loops early, set up a notification:

  1. Add a “Condition” action before the loop.
  2. If the loop exceeds 5,000 iterations, send an email notification to the admin.
  3. Example: If counter > 5000 → Send alert email “Loop limit exceeded!”

Leave a Reply

Your email address will not be published. Required fields are marked *