3 Ways to Create an Array in Power Automate

Do you need to create an array in your flow?

What is an array in Power Automate? An array is an ordered list of items.

When you get data in your flow from an external source such as a SharePoint list, a Dataverse table, or an Excel table it will be an array of records for each row of data. So arrays will be quite common in a flow.

You might find you need to create your own arrays when working in a flow. This is also possible.

This post is going to show you how you can make an array in Power Automate.

Create an Array with a Compose Action

The compose action is very versatile and it’s a great place to create static constants used in your flows or perform calculations with expressions.

You can even use it to create an array.

[
 "A",
 "B",
 "C"
]

The above example shows an array inside a compose action. You can type out any array inside a compose action. You just need to make sure to follow a few rules.

  1. Open and close the array with the square brace [] characters.
  2. Separate each item in the array with a comma , character. Optionally, you can also use space characters and/or line breaks characters after each comma.
  3. String values should be encased in quote mark "" characters. Number values don’t need any quotation marks.
  4. You can use dynamic content for an item in the array. The dynamic content doesn’t need to be encased in quote characters if it’s a string value, but it can be.
  5. The compose action shouldn’t contain anything outside the square brace characters if you want to use it as an array.

This array can now be used inside an Apply to each step.

Create an Array with the createArray Function

Arrays are so crucial to Power Automate that there is a dedicated workflow function for creating them.

createArray(<item1>,<item2>,...,<itemn>)

The createArray function allows you to create an array by listing the items for the array as arguments of the function. It’s that simple!

createArray('A','B','C')

The above example will create the array ["A","B","C"] with three items.

Notice in the expression that the string values must be encased with a single quote ' characters.

createArray('A','B','C',1,2,3)

If you want to make an array with numbers as items, you can skip the single quote characters around any number values in the createArray function.

For example, the above expression will produce the array ["A","B","C",1,2,3] with the first three items as strings and the last three items as numbers.

Create an Array with a Variable

The previous methods to create an array result in a static array that can’t easily be changed later on in your flow.

Suppose you want to create an array and then later add items to the array.

How can you do this?

You can use a variable action. These are specifically made for creating changing values.

With a variable, you’ll be able to make an array with the Initialize variable action and later use the Append to array variable action to add more items.

You can create an array with the following steps.

  1. Add the Initialize variable action to your flow.
  2. Give your variable a Name.
  3. Choose the Array option in the Type menu.
  4. Enter the initial value of your array such as ["A","B","C"]. This array entry should follow the same rules mentioned earlier when creating an array using the Compose action.

💡 Tip: You can initialize an empty array by entering the empty array as [] in the Value input of the Initialize variable action.

Now that the array has been initialized you can add more items to the array.

  1. Add the Append to array variable action below the Initialize variable action.
  2. Select your array variable name from the Name dropdown menu.
  3. Enter the value to append to your array.

In this example, the value D has been entered in the Value input area of the Append to array variable action. This will result in the array ["A","B","C","D"]. The new item is added to the end of the array.

Conclusions

Arrays are everywhere in Power Automate and you will likely need to build your own inside a flow.

Thankfully, they are quite easy to create when you know how.

You can either create your own arrays by typing them in a Compose action or by building them with the createArray function. These are both good ways to make static arrays.

If you need to create an array that you can later add items into, then you will need to create them with the Initialize variable action. You can then use the Append to array variable action to add more items to the array.

Have you built your own arrays inside a flow? How did you do it? Let me know in the comments below!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

2 Comments

  1. David Shaw

    How do you return the array to powerapps app?

    • John MacDougall

      Send it as a comma separated string and use the Split function in Power Apps?

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!