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 an array, use the “Initialize variable” action.

Set Array Value

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

Add / Append Value to Array

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

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.

Advanced Operations

Array Length / Array Size

To evaluate the size of an arry, 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'))

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]

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”.

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'),',')

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'))

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

Leave a Comment

Your email address will not be published.