Skip to content

Power Automate

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

Fastest Way To Append To Array In Power Automate (3 Methods) Posted by - Matthew Devaney on - March 24, 2024 10 Comments Knowing how to append to an array in...

Matthew Devaney
Published
Reading time
4 min read

Before you start

Is this guide for you?

Best entry point
Power Automate
Time investment
4 min read

Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/fastest-way-to-append-to-array-in-power-automate-3-methods/. Author: Matthew Devaney.

Fastest Way To Append To Array In Power Automate (3 Methods) Posted by - Matthew Devaney on - March 24, 2024 10 Comments

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 Array

Method #1: Append To Array With Variables

Method #2: Append To Array Using The Compose Action

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

Comparing 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. ID Name 1 Case-0001 2 Case-0002 3 Case-0003 4 Case-0004 5 Case-0005 6 Case-0006 7 Case-0007 8 Case-0008 9 Case-0009 10 Case-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' ) Code language: JavaScript ( javascript )

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' )) Code language: JavaScript ( javascript )

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. # Method Duration (seconds) 1 Append To Array With Variables 5 2 Append To Array Using Compose Action 2 3

Select 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. Did You Enjoy This Article? 😺

Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up 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 Power Automate

Save Docusign Document To SharePoint With Power Automate

Share this

Tagged

Power Automate

Have a Microsoft 365 topic idea?

Share article suggestions, community session ideas, corrections, or real-world scenarios for future nextM365 learning notes.

Suggest a topic

Keep learning Microsoft 365

Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.

Continue learning

Next action

What to do next

Browse all tutorials →