Power Automate: combine values from an Array without an Apply to each

Why?

In one of my previous posts (Power Automate: get value from Array ยป Knowhere365), we learned how to reference a property of an Array immediately using the integer index that an Array always has. However there are some cases where we get an Array with multible Objects in it and we want to combine a specific property from all those Objects in the Array without an Apply to each.

What?

This post will show how we can combine data from multiple Objects in Array without an Apply to each loop.
Because the actions in an Apply to each loop, count towards the API calls that a Power Automate user has per 24 hours, this can be very useful not only for Flow speed but also for less API calls per Flow. ๐Ÿค‘

How?

In my example, I have a SharePoint list with a People Picker column named Users that allows multiple selections:

SharePoint list with a People Picker column named Users that allows multi-selection

Because the column allows multiple selections, Power Automate treats the output of this Users column as an Array (with multiple Objects in it). This means that if we reference a property in this Users column in our Flow, it automatically puts the action in an Apply to each loop:

Power Automate Flow with an Apply to each loop because of an Array

If we then wanted to send all the persons in this column one email all together, we would need to use something like a string variable and an Append to string variable action:

Power Automate Append to string variable action

This adds every Email address separated by the semicolon (;) to one big string variable that can be used to send an email to. Again: a lot of work and a lot of Flow API calls to get a small piece of information just sitting in one SharePoint column…

In the following part of the blog post, I am using the DisplayName property of the persons in the Users column instead of the Email property. This is because in my tenant not all persons have working email addresses, making the Email property of these persons output to null.

1) We can avoid the Apply to each loop by first using a Select action on the Users column (giving an Array as output):

Power Automate Select action

This action gives us the option to map properties from an existing Array to a new more simple Array.
The expression in the From is simply the column of the SharePoint item:

@{outputs('Get_item_-_1ofListA')?['body/Users']}

The expression in the Map is an Object itself to map properties to a key we define ourselves
(use the icon on the right to switch between key value mode(screenshote above) and text mode(code below)):

{
  "KeyUserName": @{item()?['DisplayName']}
}

The output of this action results in a new Array with only the mapped properties that we need:

Power Automate Select action executed

2) With the output of this Select action, we can simply join it to one big string and replace all the text parts that we do not need:

Power Automate Compose action on Select output

We can do this with an expression that joins the output of the simplified Array to one big string and then replaces the unneeded information like:

replace(replace(replace(join(body('Select_-_UserNames'),','),'{"KeyUserName":"',''),'"}',''),',',';')

This leaves us with a cleaned-up string of DisplayNames separated by the semicolon:

Power Automate Compose action on Select output executed

We can then simple reference the output of this Compose action in an action where the string is needed ๐Ÿ˜Ž

6 thoughts on “Power Automate: combine values from an Array without an Apply to each

  1. Thanks for the pointers.

    Used your tip: the icon on the right to switch between key value mode and text mode.

    Then in text mode, I was able to just enter the item into the Map field (no json object/array brackets, no key names).
    It then outputted a nice array of just those values (no key names).

    This way, it skips the replace functions that strip out the key names.

Leave a comment