Skip to content
Home » Solved: How to Get Rid of Apply to Each Loops in Power Automate

Solved: How to Get Rid of Apply to Each Loops in Power Automate

If you’re struggling with unnecessary Apply to Each loops in Power Automate, you’re not alone. Many users encounter this issue when automating workflows that involve retrieving data from a single record, only to have Power Automate trigger loops because it detects an array. These loops can slow down your flow and add unnecessary complexity. In this tutorial, we’ll show you how to remove Apply to Each loops by using the First() expression in Power Automate. By following these steps, you’ll improve the efficiency of your workflows and optimize Power Automate performance, allowing your flows to run smoother and faster, whether you’re working with Microsoft Flow, large datasets, or enterprise-level automation.

If you’ve ever built a Power Automate flow and wanted to retrieve data from a single record, you might have experienced the frustration of an unwanted “Apply to Each” action. This happens when Power Automate detects an array, even if you only expect a single result. Fortunately, there’s a simple solution to this common problem. In this guide, we’ll show you how to avoid those pesky loops and improve the efficiency of your flows.

The Problem: Power Automate and Apply to Each

Imagine you’re working on a flow where you need data from just one record. You use the List Rows action to find the record, but when you go to utilize that record in subsequent steps, Power Automate wraps your actions in an Apply to Each loop. This happens because the output from the List Rows action is an array, and Power Automate assumes you need to process each record in that array, even if there’s only one.

While it’s possible to limit the rows returned to one, Power Automate still detects it as an array, which leads to the frustrating Apply to Each loop.

The Solution: Using the First Expression

To bypass this problem, you need to extract the first (and potentially the only) record from the array. This can be done using the First() expression, which effectively converts the array into a single object.

Here’s how you can implement it:

first( outputs('Array_Action')?['body/value'] )?['Field Schema Name']
  1. Create Your List Rows Action
    Start by setting up your List Rows action as usual. This will retrieve the records based on the criteria you specify.
  2. Apply the First Expression
    Use the above expression to retrieve only the first record from the array. Be sure to update the schema names of your actions/fields accordingly.
  3. Accessing a Specific Field
    If you need a specific field from the record, append the field’s schema name to the expression like in the code above. This will return the value of the specific field without triggering an Apply to Each loop.

Removing unnecessary Apply to Each loops helps streamline your Power Automate flows. Not only does this make your flows cleaner, but it also reduces processing time, making your automation more efficient. This is especially important when working with large datasets or frequent processes, where small improvements can have a big impact.

Further Optimization: Configure Run After Settings

Another way to enhance your flows is by configuring the Run After settings. This allows you to control the execution of actions based on the success or failure of previous actions. Learn more about optimizing your Power Automate flows by checking out this guide on configuring Run After settings.

Example Scenario: Emailing a System User

Let’s consider a practical example. Suppose you need to send an email to a system user based on certain criteria. You use the List Rows action to find the user, but when you try to add the user’s email to the Send an Email action, it triggers an Apply to Each loop.

By applying the First() expression and specifying the email field, you can bypass the loop and retrieve just the user’s email address. This extracts the email of the first user found, which you can then use in your email action.

Conclusion

By using the First() expression to bypass unnecessary loops, you can take control of your Power Automate flows and make them more efficient. Whether you’re working with large datasets or simply trying to speed up your processes, this simple trick can make a big difference.

Thank you for following along with this tutorial. Happy Developing!