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 / ForEach within ForEach...
Power Automate
Unanswered

ForEach within ForEach causing issues

(0) ShareShare
ReportReport
Posted on by 6
I'm having issues where a ForEach gets added to the flow and I end up in a loop. It would be good to understand where I am going wrong. In this specific example:
 
I have a table. The main columns are DisplayName, TeamID, ChannelID. I am trying to get the TeamID from the table, lookup the channels within the Team, find the one that matches the DisplayName and then save that ID back to the table.
TeamID is not unique and may exist more than once. DisplayName will be unique. In this example there are 46 rows and TeamID has two different values.
 
It seems that the first TeamID found runs quickly. The results take 60seconds to complete. Then there is a pause of around 30 minutes and the second ID is processed and these then complete in around 30seconds
 
1) List the rows
 
2) List the channels (ForEach automatically created)
 
 
3) 
 
Find the channel ID that matches DisplayName row and save back to table (ForEach1 automatically added)
 
 
 
Annoying it does work, but there is a big delay and it looks like a loop to me. The first ForEach finds the 46 rows, but ForEach1 finds only 29. 
 
Until record 29 which then finds 20 items for the ForEach1
 
 
Any help greatly appreciated.
 
 
Categories:
I have the same question (0)
  • lbendlin Profile Picture
    8,479 Super User 2025 Season 2 on at
    Not sure what your expectation is - you have nested loops, and the performance in such a scenario depends on the iterations and what you do inside the loops.  It is well possible that one or both of your actions inside the loop result in 429 or other throttling from the data source.
     
    Refactor your flow to preload all data into arrays and then loop through the arrays.
  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at
    @AM-07041029-0 The logic of your flow needs to be adjusted. Since you want to Compare the data in your Excel Table against the channels returned from the List channels action, you need to have both of these actions OUTSIDE of an Apply to Each (aka For Each) loop.
     
     
    Both of these actions will return arrays. To cross-reference one with the other, you'll need to use a Filter Array action. If you aren't familiar with how to use a Filter Array action, you might be interested in these YT Tutorials.
     

    If you still run into issues while building your flow, share screenshots of your full flow and the logic behind it. Upload a screenshot of your flow in edit mode. Ensure you toggle off the new designer and click each action to expand it.


    In this video tutorial I’ll show you 3 practical ways to use the Filter Array action and how to use it properly.
    1️⃣ Cross-Referencing Data
    2️⃣ Filtering by Key
    3️⃣ Substring Matching

    Did you know that the Condition action has a limit of 10 conditions? Although it might look like the Filter Array action can only accept one condition—this is not true. By using the advanced mode you can enter multiple conditions into a Filter Array action with an expression.

    IN THIS VIDEO:
    ✓ 3 Ways to Use the Filter Array Action
    ✓ How to use the Scope Action to Group Actions
    ✓ How to Check the Number of Items returned from a Filter Array Action
    ✓ How to Cross-Reference Data in Excel with a SharePoint List
    ✓ How the Filter Array Action Works
    ✓ How to Access the Dynamic Content from a Filter Array Action
    ✓ How to Filter Items by a Key
    ✓ How to Filter Items by Matching a Substring
    ✓ How to Use Multiple Conditions in a Filter Array Action

    ---

    In this tutorial—I’m going to show you a quicker way to get the dynamic content from your Filter Array action—and it doesn’t require writing an expression.

    IN THIS VIDEO:
    ✓ How to Loop Through Filter Array Results in Power Automate
    ✓ Using Apply to Each with Filtered Arrays
    ✓ The Easiest Way to Access Dynamic Content from Filter Array
    ✓ Fixing Nested Apply to Each Actions
    ✓ When to Use Value vs. Body Dynamic Content
    ✓ Simplifying Power Automate Flows with Filter Array
    ✓ Troubleshooting Filter Array and Apply to Each Issues

    ---

    In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:
    1️⃣ Looping through a Single Item
    2️⃣ Creating Unnecessary Nested Loops
    3️⃣ Looping through an Unfiltered Array

    At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.

    IN THIS VIDEO:
    ✓ How to avoid the Apply to Each action with a single item array
    ✓ How to use the item() function to access dynamic content in an array
    ✓ How to prevent unnecessary nested Apply to Each action loops
    ✓ How to use the Select action
    ✓ How to convert an array to a string with the Select action
    ✓ How to use the Filter Query field
    ✓ How to count the number of items in an array
    ✓ How to use a condition control
    ✓ How to use the concurrency control
    ✓ How to set a top count
    ✓ How to use Compose actions for troubleshooting
     
     
     
    Hope this helps!

    Consider giving me a ❤️ if you liked my response!

    👉 Level up your Power Automate skills by checking out my tutorials on YouTube
    👉 Tips and Tricks on TikTok and Instagram
     
  • tom_riha Profile Picture
    10,185 Most Valuable Professional on at
     
    don't use loop inside a loop to find a specific item - use a filter instead. Inside the first loop, where you're listing all channels of the Teams add the 'Filter array' action and filter only the channel you're looking for. Take the output of the 'Filter array', it'll be just that one team, and process it. Don't loop through all the channels for all the rows, that's a lot of useless operations in the flow.
     
     
    ----------------------------------------------------------------------------------
    Did the answer solve your problem? Please click "Does this answer your question" and give it a like to help others in the community find the solution too!
     
    You can find more of my solution on the blog: https://tomriha.com
     

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 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard