Avoid unwanted apply to each steps in Power Automate

When you add dynamic content to actions you will get those unwanted apply to each actions added by Power Automate.

Wanted Apply to Each

How do you avoid these unwanted apply to each actions?

Before anything else I’m first going to have a look at the apply to each steps that are added. They are definitely not all unwanted!

Just imagine that you collect a number of files from a document library in SharePoint and then you want to process them.

So you’ve got you get files action and then you add a compose action or any other set of actions that you might want.

Then you decide to use some dynamic content from the Get files action and the Apply to each step is added by Power Automate.

So far so good and there isn’t really a problem with this Apply to each action at all. Power Automate was actually being very helpful!

Unwanted Apply to Each

Now, I will look at the unwanted Apply to each in Power Automate.

In my case I’m going to query a list in SharePoint that has a multi select field called Favourite Ice Cream using the Get item action. Another common field type that will show this same issue is with multi select people fields.

As I add dynamic content to my compose I will get an Apply to each step added again, but actually all I wanted is get the property Favourite Ice Cream out of my list item.

I don’t want this Apply to each step in this case. In one of my posts earlier this week about comparing content in Lists and Libraries, I would bump into the same issue with the select actions if I was to compare the documents based on a multi select field.

Another use case for example is when you have multiple people in an assigned to field and you want to send out a single email to multiple people.

You wouldn’t want an Apply to each that makes you send out separate emails to everybody. Assuming that you want to send out a single email to all people mentioned in a people field..

Avoiding the unwanted Apply to Each

So now the big question to answer, how do we avoid those unwanted Apply to each steps?

We will first need to look at the code behind the Apply to each and the Compose action inside the Apply to each.

The Apply to each takes the Favourite ice cream field. This array of values will then be processed inside the apply to each

outputs('Get_item')?['body/FavouriteIceCream']

Now looking at the compose action we will see the items function getting the value of each individual item.

items('Apply_to_each_2')?['Value']

Putting these two expressions together we will get the following expression

outputs('Get_item')?['body/FavouriteIceCream/Value']

If you need an explanation about this querying json then please have a look at my query json post.

When the above expression is used, the apply to each will not appear and I can do whatever I like with the data.

Quite often I’m running into these issues with the select action or send an email action, but really these Apply to each actions could appear with any action.

Note that you cannot use dynamic content to get this expression into your actions, you will have to either type the expression in the expression editor or like I did create an unwanted apply to each step first and then copy the expressions created into an editor and merge the bits that you need.

Personally I use notepad as it is plain and simple but any editor will do.

Further posts about apply to each steps

https://sharepains.com/2018/11/13/microsoft-flow-single-item-nested-arrays/

https://365corner.pl/2020/02/07/power-automate-without-loop/

Share
Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

View Comments

Recent Posts

Create Distinct filters for Power Apps galleries

So you add a gallery to your app in Power Apps and you want to…

2 days ago

Send push notifications to start your app in Power Apps

Have you ever wanted to send push notification to people's phones to run a Power…

7 days ago

Patch the Common Data Services with Power Apps

Using the patch Function to update records in the Common Data Services can be easy,…

1 week ago

Deploy Canvas Apps and Flows through solutions

When you deploy Canvas Apps and Flows in Power Apps and Power Automate you can…

2 weeks ago

Address Input in Power Apps

When you app needs users to input addresses, you can now use the Address input…

2 weeks ago

Just 3 clicks to disable an action in Power Automate

Have you ever wanted to disable an action in your Power Automate flow? It is…

3 weeks ago
%%footer%%