Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
Menu

Stop Power Automate flow from adding ‘Apply to each’ automatically

Posted on November 21, 2021January 28, 2022 by Tom

“Sometimes, when I use specific dynamic content, Power Automate adds the ‘Apply to each’ action automatically, how can I stop it? I don’t want to repeat any of the actions!”


You surely encountered this when building a Power Automate flow. You add the actions you need and use the available dynamic contents to configure them. It goes fine, until you add that one dynamic content. Once you add it, it’ll add ‘Apply to each’ around the action. And that’s where the problems can start. The flow will send multiple emails instead of one. It’ll create duplicate SP items instead of one item with multiple values. Or it could just stop working completely. Why does Power Automate do it and what can you do about it?

Power Automate stop apply to each

Why is it adding ‘Apply to each’?

Power Automate adds ‘Apply to each’ automatically every time you’re trying to access value from an array. As explained in the post on processing JSON, you can recognise arrays by the brackets [ and ]. Anytime you try to access anything inside [ ], Power Automate will automatically add ‘Apply to each’. It recognises it’s an array, and as such it wants to process all the objects/values. One by one, inside a loop.

That means, to avoid the ‘Apply the each’ you must extract the object/value from the array differently. You can’t leave it up to Power Automate.

Get rid of the array

You must extract the values from the array and turn them into a string, or select only a specific object/value from the array. There’re multiple options how to do it, depending on the array and how you want to use it.

Simple array

If it’s a simple array, you can convert it into a string with the join(…) expression.

Array of objects (pre-processing possible)

If it’s an array of object, but you have the possibility to preprocess it, you can use the ‘Select’ action together with the join(…) expression.

Array of objects (more pre-processing needed)

Sometimes, for example when working with documents, you can’t use just ‘Select’. You need an extra action, e.g. ‘Get file content’ to extract content from each of the files separately. In that situation you’ll need a loop to preprocess it.

Array of objects (pre-processing not possible)

For some actions it’s not possible to pre-process the data, e.g. ‘Create HTML table’ or ‘Create csv table’. In such situations you’ll need the xpath(…) expression together with join(…).

Taking only a specific object

The last option is to take only a specific object from the array, e.g. the first approval response. If you take only a specific object from the array, the ‘Apply to each’ won’t be needed.

The same applies also if you extract the object/value directly from the JSON.

Summary

Power Automate will add ‘Apply to each’ each time you try to process an array and the only way to stop it is to preprocess the array by yourself. The actual processing depends on what you’re trying to achieve. If you want a specific value(s), you can use one of the first 3 options. If you want the whole object for later processing, the last options is what you’re looking for.

Just don’t forget to remove the automatically added ‘Apply to each’ at the end. Otherwise it’ll keep looping even after you preprocess it.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

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

NOW AVAILABLE:

The Ultimate Power Automate expressions cheat sheet
Spend your time thinking about what the flow should do, not how to do it!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • How to create a new SharePoint list column with Power Automate flowMay 22, 2022
  • How to combine expressions in your Power Automate flowsMay 18, 2022
  • Import Planner tasks with checklists into various buckets (Power Automate)May 15, 2022
  • How to get notified when Planner task was reassigned (Power Automate)May 11, 2022
  • How to extract value from XML using Power Automate flowMay 8, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme