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.
- Open and close the array with the square brace
- 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.
- String values should be encased in quote mark
""characters. Number values don’t need any quotation marks.
- 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.
- 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.
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!
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
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.
- Add the Initialize variable action to your flow.
- Give your variable a Name.
- Choose the Array option in the Type menu.
- 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.
- Add the Append to array variable action below the Initialize variable action.
- Select your array variable name from the Name dropdown menu.
- 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.
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!