Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Triggers
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
  • Get help with flow
Menu

How to convert array to a string in Power Automate

Posted on January 31, 2021March 13, 2022 by Tom

“I have a SharePoint column with multiple choices enabled, how can I convert the data from it (array) into a string to send it in a single email in Power Automate?”


Power Automate will automatically add ‘Apply to each’ once you try to use dynamic content from an array. It’s fine if you want to process the items one by one, e.g. update multiple items or send multiple emails. But it’s not so good if you need all the items at once. If you’ve got a SharePoint column with multiple choices, you don’t want to loop through them. You want all of the choices at once, a single string in readable format. It can be user information (emails, names), choices, lookups… The usage is the same: don’t loop, convert the values to a single string.

Simple array

If it’s a simple array with a list of values (no object structure), you can use the join(…) expression. You can see an example of simple array below (created when exporting multiple Person or Group column to .csv):

[
    "xxx@tomriha.com",
    "yyy@tomriha.com"
]

The join(…) expression expects 2 parameters, the array with values, and a separator for the outcome.

join([array], '[separator]')

The example below will take the array (variable var_array), and convert into a comma separated string.

join(variables('var_array'), ', ')

Notes:
variables('var_array') is the array
', ' is definition of the separator, separator are the characters between ' and '

result:
xxx@tomriha.com, yyy@tomriha.com
Power Automate join array into string

Array with objects

It gets a bit more complicated with more complex arrays: Person or Group column, choice column, etc. Instead of just a list of values, complex arrays contain objects with multiple pairs of “key”: “value”.

"Person_MultipleSelection": [
    {
        "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        "Claims": "i:0#.f|membership|xxx@tomriha.com",
        "DisplayName": "Tomáš Říha",
        "Email": "xxx@tomriha.com",
        "Picture": "..."
    },
    {
        "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        "Claims": "i:0#.f|membership|yyy@tomriha.com",
        "DisplayName": "yyy@tomriha.com",
        "Email": "yyy@tomriha.com",
        "Picture": "..."
    }
]

Join(…) expression won’t work here as it would create a string from the whole objects. And you don’t want the whole object, you want just a specific value from that array, e.g. Email.

‘Select’ the values

The best approach is to use the ‘Select’ action. The action expects an array of objects on the input, e.g. the array with multiple users, and allows you to select only some values from it. Put the array as the input, in this example it’s the ‘Person_MultipleSelection’ dynamic content. Since you want to build a string only from the values, you should ignore the key/value mapping and switch to the text mode. That way you can skip the key and select only the values.

Power Automate 'Select' text editor

Each object in the array is represented by the expression item(), and each value by adding ?[‘Key’]. You can use any ‘Key’ from the object. The expressions below will give you all display names or emails of the users.

item()?['DisplayName']
or
item()?['Email']
PA select

Output of the ‘Select’ action will be a new array, this time a simple one, that will contain only the desired values.

PA select outputs

And as was already explained, a simple array can be converted into a string with the join(…) expression

join(body('Select'),';')
->
xxx@tomriha.com;no-reply@tomriha.com
Power Automate convert array of objects into string

Summary

When you convert an array into a string in Power Automate, the first thing to consider is: “what type of array do I need to process”? If it’s a simple array, you can use the join(…) expression. But if it’s a complex array with objects, it’ll require a ‘Select’ action first.

It’s possible to process complex arrays in a single action with a combination of expressions (as when exporting to .csv), but I believe this step-by-step approach has it’s benefits. You can track what’s happening in each step, it’s easier to debug, and much easier to explain and understand.


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.

13 thoughts on “How to convert array to a string in Power Automate”

  1. Fernando says:
    June 9, 2021 at 12:17 am

    Hi
    I’m stuck on the select values for complex arrays. I may be doing something wrong as after switching to text it doesn’t accept the expression item()?… any suggestion? Can you elaborate a bit more on that step?

    Thanks a lot

    Reply
  2. Fernando says:
    June 9, 2021 at 9:52 am

    All sorted

    Reply
  3. Rafa says:
    September 8, 2021 at 5:52 pm

    Muchas gracias desde Mexico!

    Reply
  4. KB_1234 says:
    January 27, 2022 at 9:25 pm

    I’m having an issue with multiple selections when using this flow. It works fine with one person, but when I add additional people it fails.
    “The specified user Name1, Name;Name2, Name could not be found.”
    Any suggestions?

    Reply
    1. Tom says:
      January 29, 2022 at 7:14 pm

      Hello Kara,
      it seems you’re using the string in an action that allows for only a single value. In such situations you must loop through the array and input the values one by one.

      Reply
  5. Rob D says:
    February 17, 2022 at 5:56 pm

    I’m after a path to a sharepoint library (which can change), I thought I’d use List Folder > Filter Array > Select. Which gives me a one item array. I should then use Join to turn it into a string? I guess my problem is I don’t actually have anything to join or a separator?

    I think I’m over complicating things. Any help is appreciated.

    This is a great site, thank you very much.

    Reply
    1. Rob D says:
      February 17, 2022 at 6:16 pm

      I guess I just needed the Rubber Duck to talk it out with:
      Used Filter>Select>Compose with join(body(‘Select’),”) which seems to give me what I needed. In any case, wouldn’t have gotten there without this site. Thanks!

      Reply
  6. LinC says:
    May 19, 2022 at 8:18 pm

    Hi Tom – Thanks a ton for this post. I’ve been spending sooo much time appending to array/string variables and I knew there had to be a better way. Your explanation is crystal clear and actually makes it look so simple that now I feel embarrassed not to have worked it out sooner…

    THANK YOU! 🙂

    Reply
  7. Leah says:
    June 29, 2022 at 3:21 pm

    I’m also not sure if Join is working correctly to where a string is outputted. As mentioned, I used a semicolon as the separator parameter, but the output shows a comma separator. For your awareness, the Join output looks just like the output of the previous step where I used Select due to a complex array. Example of the output of Join (notice the comma separator is shown):

    [“Email 1” , “Email 2”]

    Reply
    1. Tom says:
      July 6, 2022 at 6:50 pm

      Hello Leah,
      your output is an array (the opening and closing [ ] ), it’s not a string. I’d double check the dynamic content that you apply the join(…) to.

      Reply
  8. Frank says:
    September 16, 2022 at 1:44 pm

    Excellent 🙂

    Reply
  9. Stuart Harrod says:
    October 14, 2022 at 8:32 pm

    Yes, this is a great and straightforward solution. Thank you

    Reply
  10. Carl Williams says:
    December 8, 2022 at 12:37 am

    WOW, this is exactly what I was looking for!!!! Even for the emails. Thanks-you so much!

    Reply

Leave a Reply Cancel reply

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

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


NEW! Master the HTTP requests to SharePoint with a new cheat sheet!

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.

  • Use Power Automate to forward Outlook events upon registrationJanuary 29, 2023
  • Why the condition is false for the same numbers (Power Automate)January 25, 2023
  • How to forward event invitation to other calendar (Power Automate)January 22, 2023
  • Run ‘For selected item’ flow from non-default environment (Power Automate)January 18, 2023
  • Hide button in SharePoint list after Power Automate flow startedJanuary 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes