Build Arrays Faster in Power Automate: Three Techniques Compared
Collecting items into an array is a routine task in automation. The technique you choose—variables, compose, or the Select action—can drastically influence flow execution time.
Power Automate developers often need to gather individual items—such as records from a loop, query results, or computed values—into a single array for later processing. The way you build that array can vary, and not every approach performs equally. This article compares three common techniques: using a variable with an append action, collecting objects through the Compose action, and transforming items with the Select action. We’ll examine their performance characteristics and when each makes sense.
Scenario: Building an Invoice Items Array
Imagine you need to create an array of invoice line items from a list of order numbers. For our demonstration we generate 10 item identifiers and turn each into an object with three properties: InvoiceID, Product, and Qty.
| InvoiceID | Product | Qty |
|---|---|---|
| INV-0001 | Product 1 | 1 |
| INV-0002 | Product 2 | 2 |
| INV-0003 | Product 3 | 3 |
| … | … | … |
| INV-0010 | Product 10 | 10 |
We’ll use the same base data ([ range(1,11) ]) for each method so the comparisons are fair.
Method 1: Using a Variable and Append Action
This is the most straightforward approach but often the slowest for large datasets.
Steps
- Initialize a variable – create a variable named
arrInvoicesof type Array with a default value of[]. - Add an Apply to Each – set its input to
range(1,11). - Inside the loop – use a Compose action to build the object for the current item.
- Append to Array Variable – add the output of the Compose action to
arrInvoices.
The Compose action uses an expression like this:
{
"InvoiceID": concat('INV-', formatNumber(items('Apply_to_each'), '0000')),
"Product": concat('Product ', items('Apply_to_each')),
"Qty": items('Apply_to_each')
}The Append to Array Variable action then selects the Outputs of that Compose as the value.
Loops that contain variable writes (like Append to Array Variable) cannot use concurrency control. This forces sequential execution and is the main reason this method lags behind the others.
Method 2: Composing Objects and Collecting Outside the Loop
Instead of writing to a variable on each iteration, this technique builds a temporary array of all iteration outputs by referencing them after the loop.
Steps
- Apply to Each – input
range(1,11). - Inside the loop – same Compose action to create the object (as in Method 1).
- Outside the loop – add a new Compose action with the following expression:
outputs('Compose_InvoiceObject')- Enable concurrency in the Apply to Each settings (set the degree of parallelism to 50, for example).
Because the Compose inside the loop runs simultaneously in multiple threads, and we only read its outputs after the loop, this method runs significantly faster than the variable approach. The final array is the result of the outer Compose.
Method 3: Using the Select Action (No Loop)
The Select action transforms an array without needing an iterative loop at all. This is the fastest method when your transformation can be expressed as a direct mapping from input values.
Steps
- Add a Select action.
- In its From field enter
range(1,11). - In the Map section, define the output fields:
InvoiceID : concat('INV-', formatNumber(item(), '0000'))
Product : concat('Product ', item())
Qty : item()The Select action emits the final array of objects directly. No loop, no variable, no extra Compose. Power Automate processes all items in one pass, giving the best possible performance.
Performance at a Glance
| Method | Loop Required | Concurrency Support | Approximate Time (10 items) | Time Trend with Larger Data |
|---|---|---|---|---|
| Variable & Append | Yes | No | Several seconds | Grows linearly, slowest |
| Compose (collect outputs) | Yes | Yes | ~2 seconds | Grows, but scale less |
| Select action | No | N/A | <1 second | Nearly constant relative |
The exact durations depend on your region and flow environment, but the Select action consistently finishes in a fraction of the time of the others, especially as the number of records increases.
Understanding Concurrency Constraints
Power Automate’s Apply to Each loop supports parallel execution, but only if it contains no variable operations (read or write). Both the variable and compose methods use a loop, but:
- The variable method cannot enable concurrency, so it is stuck with sequential execution.
- The compose method avoids variable actions, so concurrency can be turned on, yielding a 3–5× speedup over the variable approach.
- The Select action doesn’t need a loop at all, sidestepping the concurrency question entirely.
Common Pitfalls
- Missing variable initialisation – Using Append to Array Variable on an uninitialised variable will cause an error.
- Incorrect
outputs()reference – When collecting outputs outside the loop, the action name in the expression must exactly match the Compose action inside (including spaces). Use dynamic content if possible to avoid typos. - Select action with complex logic – If you need to perform API calls, conditionals, or multi-step transformations per item, a loop is unavoidable. The Select action cannot call other action types.
- Unintended single output – Using
outputs('Compose_...')outside a loop when the Compose is not inside a loop returns only the last object, not an array.
Which Method to Choose
| Scenario | Recommended Method |
|---|---|
| Simple transformation of a range or existing array | Select action |
| Building array after performing actions inside a loop | Compose (with concur.) |
| Need to conditionally add items to an array while in a loop | Compose (or variable if compatibility required) |
| Very small array (e.g., fewer than 10 items) and simplicity > speed | Variable method (acceptable) |
For most routine array‑building tasks, the Select action offers the best performance and simplest design. When a loop is necessary, prefer the Compose method with concurrency enabled. Reserve the variable‑based approach for cases where you must modify the array dynamically inside the loop and cannot change the variable to a compose pattern.
References
- Original article that explored this topic: Matthew Devaney, “Fastest Way To Append To Array In Power Automate”
- Microsoft Learn: Apply to Each – Power Automate
- Microsoft Learn: Select action – Power Automate
- Microsoft Learn: Concurrency settings
Core principles for resilient, maintainable, and efficient cloud flows, distilled from real-world implementations.
Build flows that gracefully handle failures and automatically notify you with run details.
Discover the trade-offs between Content-ID, Base64, and the Microsoft Graph API for embedding images in Power Automate emails. This guide covers which method works best for Outlook, Gmail, and more.