Citizen Developer
Timespan
explore our new search
​
Power Automate: Avoid ForEach & Apply
Power Automate
Jan 28, 2026 1:07 AM

Power Automate: Avoid ForEach & Apply

by HubSite 365 about Andrew Hess - MySPQuestions

Currently I am sharing my knowledge with the Power Platform, with PowerApps and Power Automate. With over 8 years of experience, I have been learning SharePoint and SharePoint Online

Power Automate expert guide to escaping Apply to each using arrays versus objects, first, flatten, Select and Join

Key insights

  • Apply to Each appears automatically when an action returns an array.
    Power Automate wraps follow-up actions in a loop whenever it detects list-style output, which can add unnecessary steps for single results.
  • Array vs Object: arrays are ordered lists (indexes start at 0) and objects are single records with named properties.
    Choose direct access for objects and index or transform arrays before processing to avoid loops.
  • Two simple escape methods: use first() or [0] to grab a single value, or flatten the array to remove nested lists.
    Both approaches let you avoid Apply to Each when you only need one value or a flat structure.
  • Use Select, join(), and append to string to reshape or combine array items.
    Select maps array fields, join() combines values into one string, and join often outperforms repeated append actions.
  • Concurrency and pagination speed up large collections: enable concurrency (up to 50 threads) for parallel processing, and turn on pagination to retrieve many rows.
    Use these when you must process large datasets without looping one-by-one.
  • ForEach practical tips: delete unnecessary loops, add a Compose action with first(body('Get_Items')?['Title']) to extract one field, and test with sample data.
    Always check action names, watch for zero-based indexes, and pick the escape method that matches your data shape.

Introduction

In a recent YouTube video, Andrew Hess - MySPQuestions examines a common source of confusion in Microsoft Power Automate: the automatic insertion of Apply to Each (also shown as ForEach in the newer designer). He explains why these loops appear unexpectedly and shows practical ways to avoid or simplify them when they are not needed. Overall, his walkthrough focuses on understanding the shape of data and choosing the right expression or action to prevent unnecessary iterations. Consequently, the video aims to help makers reduce flow complexity and improve execution time.


Why Loops Appear and How Data Shapes Behavior

Hess begins by clarifying that Power Automate inserts Apply to Each when an action outputs a collection, such as multiple rows from Excel or several items from SharePoint. He contrasts a single-value response with an array and an object, noting that the platform treats collections differently and therefore nests subsequent actions inside a loop. As a result, many users see loops even when they expect only one value, which leads to confusion and extra work. Therefore, recognizing whether the output is truly a multi-item array or a single object is the first practical step toward simplification.


Two Main Ways Out of Unnecessary Loops

The video highlights two primary strategies for "escaping" a loop: grabbing a single value directly, or flattening the array so the flow no longer treats the data as a collection. For a single value, Hess shows how functions like first() or index access such as [0] can extract the element without an explicit loop. In contrast, flattening involves transforming nested arrays into a single-level collection, using actions such as Select followed by Join, or by using expressions that combine elements into a string and then split them as needed. These approaches avoid redundant iterations but carry tradeoffs related to readability and error handling.


Techniques, Tradeoffs, and Practical Examples

Hess demonstrates the practical steps to implement each technique, for example using a Compose action with the expression first(body('Get_Items')) to directly access a title from a SharePoint result that has only one item. He also shows how flattening with Select and Join can consolidate values when you truly need a single string rather than multiple records. However, he warns that using first() or direct indexing risks missing data when the collection unexpectedly contains zero items, and that flattening can obscure individual item errors, making debugging harder. Thus, the tradeoff becomes a balance between speed and resilience: fewer actions and faster runs often reduce transparency when things go wrong.


Concurrency, Performance, and Error Handling

Beyond escaping loops, Hess touches on performance levers such as enabling concurrency in the loop settings and using pagination for large datasets. Concurrency can speed processing by running multiple iterations in parallel, but it can also introduce race conditions or exceed connector limits if upstream systems cannot handle parallel requests. Pagination helps retrieve many rows without forcing many small calls, yet it changes how you handle large results and may increase memory use. Consequently, makers must weigh speed gains against increased complexity in error handling and potential throttling from connectors.


Challenges and Best Practices

Hess emphasizes that there is no single "right" method; rather, the best approach depends on the data and the desired outcome. He recommends inspecting action outputs in run history to confirm whether you have an array or object, using defensive expressions to handle empty results, and keeping flows readable by grouping related work into child flows when necessary. Moreover, he suggests that developers document why they chose first() or a flattening pattern to make future troubleshooting simpler and to guide colleagues who inherit the flow. In short, thoughtful tradeoffs and clear comments improve maintainability.


Conclusion

Andrew Hess’s video offers clear, approachable guidance for makers who want to avoid automatic loops in Power Automate without sacrificing correctness. By explaining the underlying data shapes and showing hands-on expressions and actions, he provides a toolkit that balances performance, clarity, and resilience. Ultimately, the choice between extracting a single value, flattening arrays, or using concurrency depends on the particular scenario, and the video helps viewers evaluate those tradeoffs. For teams aiming to streamline flows, the demonstrated methods are practical starting points that encourage careful testing and documentation.


Power Automate - Power Automate: Avoid ForEach & Apply

Keywords

escape Apply to each Power Automate, avoid ForEach Power Automate, bypass Apply to each performance, parallelize loops Power Automate, use Select instead of Apply to each, concurrency control Power Automate, optimize Power Automate loops, reduce iterations Power Automate