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

Sharing flows in Power Automate

Recently I tried to share a flow and I got trial warning. it took a…

40 mins ago

There’s a problem that needs to be fixed in Power Automate

Have you ever had your flows showing the following error: There's a problem that needs…

1 day ago

Get started with child flows in Power Automate

Child Flows is one of the subjects that has been on my list of things…

5 days ago

Implementing 2 levels of grouping in Power Apps

When you want to implement 2 levels of grouping in Power Apps you will discover…

1 week ago

Power Automate Approvals and Dataverse

Power Automate Approvals are often one of those unclear things that people try to avoid.…

2 weeks ago

Modern app designer vs Classic app Designer in Model Driven Apps

When you create a new Model Driven App today, you will find that you have…

2 weeks ago
%%footer%%