Fastest Way To Append To Array In Power Automate (3 Methods)

Fastest Way To Append To Array In Power Automate (3 Methods)

Knowing how to append to an array in Power Automate is useful because you can take a set of individual objects and add them into a single array. Or to speak plainly, you can create a series of rows and combine them into a table. Using the append to an array variable action is the most obvious method but there are other techniques that are much faster.

Table of Contents
• Introduction: The Case ID ArrayMethod #1: Append To Array With VariablesMethod #2: Append To Array Using The Compose ActionMethod #3: Use The Select Action Instead Of Append To ArrayComparing Append To An Array Methods Performance




Introduction: The Case ID Array

We will explore how to use Power Automate to create an array of Case IDs. Each array item has an ID and Name as shown in the table below.

IDName
1Case-0001
2Case-0002
3Case-0003
4Case-0004
5Case-0005
6Case-0006
7Case-0007
8Case-0008
9Case-0009
10Case-0010




Method #1: Append To Array With Variables

The first method we will use to “append to an array” in Power Automate uses variables. We start by initializing an empty array variable named varCaseArray. Then we generate a range of the numbers 1-to-10 and loop over them in an Apply To Each action. Inside of the loop we format the case number and use the Append To Array Variable action to add the result to the array.



Write this code in the Select output from previous steps field of the Apply To Each action to generate an array of the numbers 1-to-10.

range(1,10)



When the flow is run the array is output into a Compose action containing the case id and name.




Method #2: Append To Array Using The Compose Action

The second method to “append to an array” in Power Automate removes variables and the Append To Array Variable action from the flow. Instead, we use Compose as the final action inside the Apply To Each loop to create objects (i.e. individual array items). Then we assemble all of the objects into an array using the another Compose action outside of the loop.



Write this code in the Select output from previous steps field of the Apply To Each action to generate an array of the numbers 1-to-10.

range(1,10)



Then use this expression in the Compose: Case Array Variable Method action to take the Case objects and append them to an array.

outputs('Compose:_Case_Array_Object')



To make the Apply To Each action run faster go to the settings and enable concurrency control. This allows the loop to process several threads at once instead of running them sequentially. We could not do this in the “append to array with variables” action because concurrency cannot be used in loops which contain variables.



Once again, we can run the flow and see an array inside the Compose action containing the case id and name.




Method #3: Use The Select Action Instead Of Append To Array

The third and final method to “append to an array” in Power Automate uses the Select action



Write this code in the Select output from previous steps field of the Select action to generate an array of the numbers 1-to-10.

range(1,10)



In the Map field, use the current item as the id value.

item()



And write this code for the name value to generate a case name in the format of “Case-0001”.

concat('Case-',formatNumber(item(),'0000'))



When we run the flow the Select action outputs an array containing the case id and name just as the other methods using Apply To Each did.




Comparing Append To An Array Methods Performance

Now we know 3 methods we can use to append to an array in Power Automate. But which method should you use? The Select Action method is the fastest, followed by the Compose Action method. The appending to an array using variables method is the slowest.

#MethodDuration (seconds)
1Append To Array With Variables5
2Append To Array Using Compose Action2
3Select Action Instead Of Append To Array<1



Here is screenshot of the flow run used to create the Case ID array with all of the different methods as proof. Remember, the examples we worked through only had 10 records. Performance will improve greatly as the number of records appended to the array becomes larger.






Questions?

If you have any questions or feedback about Fastest Way To Append To An Array In Power Automate (3 Methods) please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Matthew Devaney

Subscribe
Notify of
guest

4 Comments
Oldest
Newest
Inline Feedbacks
View all comments
shalem120
shalem120
27 days ago

Thanks, Matthew, for another great post. These Select magics are pretty cool. The one from last week with validating allowed characters was awesome as well.

In the second method you used the wrong screenshots (the variable is used as the dynamic value for the outer compose action) and you called it Case Array Variable Method, which is confusing because Variable is method 1. But it is less important because the 3rd method is why we are here today…

L Hewitt
L Hewitt
24 days ago

In #2, I had NO CLUE that the using the outputs of compose outside a loop would create an array – this changes so much!!! It feels so counterintuitive since the actions within a loop are usually untouchable outside of it.