Power Automate Arrays: The Common Operations Guide

Power Automate Arrays

Arrays are the collection type within Power Automate. They are an essential part of most Flows. This article explains how basic and advanced operations on arrays within a Power Automate Flow are implemented.

Since the article is created as a learning notebook for myself, you might know better solutions to a described problem. Do not hesitate to drop me a line, so I can adjust the article and learn from you.

The Basics

Create Array Variable / Initialize Array Variable

To create a Power Automate array variable, use the “Initialize variable” action.

power automate convert array to string 2
Power Automate Create array / Power Automate initialize variable array with values

Set Array Value

To set the value of an existing Power Automate array variable, use the “Set variable” action. (Overwrites current value.)

power automate set array 1
Power Automate Set array variable

Add / Append Value to Array

To add a value to a Power Automate array, use the “Append to array variable” action. The sample below appends the string “purple” to the existing array colors.

power automate add value to array
Power Automate append to array variable

Loop / Iterate over Array

To iterate over an array, use the “Apply to each” action.

In the example below 4 notificatrion emails are sent. One for every array element.

popwer automate iterate over array

Advanced Operations

Array Length / Array Size

To evaluate the size of an array, use the length function.

In the example below, the condition evaluates to “true”, because the defined array “colors” has 3 elements.

Note: The length function can be used for variables of type array or string.

length(variables('colors'))
power automate array length
Power Automate length of array condition

Access Array Element by Array Index

To access an array element by index, you can use the [<index>] from like below.

In the example “second color in array” will be “blue”. (Note: Index starts at zero=
‘green’)

variables('colors')[1]
power automate array index 1
Power Automate Array index

Convert / Concat Array to String / Join Array to String

To convert an array to a string, use the Join action. Define the seperator to concat the values within the Join with option.

The result of the example below will be “green,blue,red”.

power automate convert array to string 1

Convert a String to Array / Split a String into Array

To split a string into an array, you can use the split functions as follows.

The result of this example will be an array with these values: [ “green”,  “blue”,  “red”]

split(variables('colors as string'),',')
power automate convert string to array

Sort Array

To my surprise, there is no sort function or action.

I’ve found these resources for workarounds.

Let me know, if there is a simpler solution.

Remove Duplicates from Array

To remove duplicate elements in an array, use the union function.

Note that we have to use the same array twice in our example.

The resulting array contains “blue” once.

union(variables('colors'),variables('colors'))
power automate array remove duplicates

3 thoughts on “Power Automate Arrays: The Common Operations Guide”

Leave a Comment

Your email address will not be published.