← Al Davies, 250 High Street

How to combine two arrays in Power Automate

Use the union() expression. Write union(variables('ListA'), variables('ListB')) in a Compose action. It returns one array with the items from both lists, and it drops repeated items.

What does union() do in Power Automate?

The union() function merges the collections you pass in into one. Microsoft documents it as union([collection1], [collection2], ...). It needs at least two collections, and they must be the same type: all arrays or all objects.

Microsoft shows this example: union(createArray(1, 2, 3), createArray(1, 2, 10, 101)) returns [1,2,3,10,101]. A value found in both lists, like 1 or 2, is returned a single time.

How do you combine two arrays step by step?

  1. Build or load both arrays first. For example, use two Select actions or two array variables.
  2. Add a Compose action below them.
  3. Select the input box and open its Expression tab.
  4. Type union(outputs('Select'), outputs('Select_2')), with the names of your own actions.
  5. Choose Add, then save the flow and run it.
  6. Open the run history and check that the Compose output shows items from both lists.

Does union() remove duplicate items?

Yes, for simple values. In the Microsoft example above, the repeated 1 and 2 show once. Use this to your advantage when you want a clean list, such as the email addresses from two groups with no repeats.

To remove repeats from one list, see remove duplicates from an array in Power Automate.

How do you combine two arrays and keep the duplicates?

The union() function does not keep repeated values, so it is the wrong tool here. Use an Apply to each loop on the second array. Inside the loop, add an Append to array variable action that adds each item to the first array variable.

This method is slower on large lists because the flow runs the loop once for each item. Test with your real volume. If your source is a SharePoint list, check that the Get items action returned every row first. See why Get items returns only 100 rows.

How do you find the items two arrays share?

Use intersection(). It returns only the items that appear in every collection you pass. Microsoft shows intersection(createArray(1, 2, 3), createArray(101, 2, 1, 10), createArray(6, 8, 1, 2)) returning [1,2].

Use it to find, for example, the people who are on both an approvers list and an active staff list. To keep rows that match a rule instead of matching another list, use a Filter array action.

Why does union() fail or return fewer items than expected?

Check three things. First, both inputs must be arrays. A single value or a text string causes a type error. Second, an empty or null input can fail the expression. Wrap the input with coalesce(), such as coalesce(outputs('Select'), createArray()). Third, for objects Microsoft says that when items share a name, the last one wins, so test on a small list before you trust it on real data.

If you need one text line from the combined list, add a Join action after the union.

FAQ

Is there a Merge arrays action in Power Automate?

No single action does this. Use the union() expression in a Compose action, or loop with Append to array variable.

How many arrays can union() combine?

The reference shows a list of collections with no fixed small limit. Pass the arrays as separate arguments, separated by commas.

Does union() change the original arrays?

No. It returns a new array. Use that output in later steps.

Sources