Post

#PowerPlatformTip 24: 'Merge Arrays or Tables in Power Automate'

Merge, combine or join two arrays in Power Automate: union() removes duplicates, the join/concat/split pattern keeps them. Both expressions ready to copy.

#PowerPlatformTip 24: 'Merge Arrays or Tables in Power Automate'

TL;DR: Merge two arrays and keep duplicates by joining each with a delimiter, concatenating, then splitting back, instead of union which drops duplicates.

💡 Challenge

You need to merge two arrays in Power Automate but keep the duplicates. The union function merges arrays, but it removes duplicates and returns only unique values.

🔀 Combine Two Arrays: union() vs. join/concat/split

There are two ways to combine (merge, join) two arrays in Power Automate – pick the one that matches your duplicate requirement:

Method Expression Duplicates
union() union(outputs('array1'), outputs('array2')) ❌ removed
join → concat → split split(concat(join(array1, '||'), '||', join(array2, '||')), '||') ✅ kept

Power Automate real flow run: union([1,2],[2,3]) returns [1,2,3], the duplicate 2 removed Real flow run: union([1,2],[2,3]) → [1,2,3], the duplicate 2 is gone.

Power Automate real flow run: join-concat-split on the same two arrays returns [1,2,2,3], the duplicate kept Same two arrays through join → concat → split → [1,2,2,3], the duplicate 2 survives.

There is no built-in merge() or combine() function – union() and the join/concat/split pattern below cover both cases.

flowchart TD
    A["Merge two arrays"] --> B{"Keep duplicates?"}
    B -->|No| C["union(array1, array2)"]
    B -->|Yes| D["join each array with delimiter"] --> E["concat both strings"] --> F["split back into an array"]

✅ Solution

Instead of union, concatenate the arrays with a unique delimiter and then split the result back into an array. This preserves every element, including duplicates.

🔧 How It’s Done

  1. Join each array into a string using a unique delimiter (||).

  2. Concatenate both strings, keeping the delimiter between them.

  3. Split the combined string back into an array using the same delimiter, all elements, duplicates included, are restored.

Here’s the expression:

1
2
3
4
5
6
7
8
split(
  concat(
    join(outputs('Compose_-_2_arrays')?['array1'], '||'),
    '||',
    join(outputs('Compose_-_2_arrays')?['array2'], '||')
  ),
  '||'
)

🧱 Arrays of Objects: Merge, Keep Duplicates, Deduplicate

The pattern above is built for simple values. With arrays of objects (SharePoint items, Dataverse rows, JSON records) three things change. All results below come from one flow run with array1 = [{"id":1,"n":"A"},{"id":2,"n":"B"}] and array2 = [{"id":2,"n":"B"},{"id":3,"n":"C"}].

1. union() works on objects and removes identical ones.

🔸 union(array1, array2) returns [{"id":1,"n":"A"},{"id":2,"n":"B"},{"id":3,"n":"C"}], the object {"id":2,"n":"B"} appears once.

🔸 Property order does not matter: {"id":1,"n":"A"} and {"n":"A","id":1} count as the same object, the union of both holds one element.

🔸 union() takes more than two arrays: union([1,2], [2,3], [3,4]) returns [1,2,3,4].

2. join/concat/split loses types.

🔸 join() serialises each object to JSON text, join(array1, '||') returns {"id":1,"n":"A"}||{"id":2,"n":"B"}. After split() you have an array of strings, not objects.

🔸 The same happens with numbers: [1,2] and [2,3] through join/concat/split come back as ["1","2","2","3"].

3. Merge and keep duplicates without losing types.

🔸 Serialise both arrays, glue them at the ][ seam and parse again:

1
json(replace(concat(string(array1), string(array2)), '][', ','))

🔸 Returns [{"id":1,"n":"A"},{"id":2,"n":"B"},{"id":2,"n":"B"},{"id":3,"n":"C"}], four real objects, the duplicate kept. With [1,2] and [2,3] it returns [1,2,2,3] as numbers.

4. Remove duplicate objects from one array.

🔸 union(variables('merged'), json('[]')) on the four-element array above returns the three unique objects.

🎉 Result

You merge both arrays while keeping all duplicate values, something the standard union function does not allow.

🌟 Key Advantages

🔸 Inclusivity: every element is kept, duplicates included.

🔸 Flexibility: adjust the formula for simple lists or more complex data structures.

🔸 Power: manipulate data in ways the standard functions don’t directly allow.

🛠️ FAQ

1. How do I combine two arrays in Power Automate?

Use union(array1, array2) if duplicates may be removed, or the join/concat/split pattern above if every element must be kept.

2. How do I merge two arrays without removing duplicates?

union() always deduplicates. To keep duplicates use: split(concat(join(array1, '||'), '||', join(array2, '||')), '||').

**3. What happens if my array contains values that include the delimiter ‘   ’?**

Choose a unique delimiter that doesn’t appear in your data, or use a more complex delimiter like ‘###DELIMITER###’.

4. Can this method handle arrays with different data types?

join/concat/split always returns strings: [1,2] and [2,3] come back as ["1","2","2","3"]. To keep numbers, booleans or objects, use json(replace(concat(string(array1), string(array2)), '][', ',')) instead, it returns [1,2,2,3] with the original types.

5. Is there a performance impact when merging large arrays?

For very large arrays, consider using the union() function for simple merging without duplicates, or batch processing for better performance.

6. How do I merge two arrays of objects in Power Automate?

union(array1, array2) merges object arrays and removes objects that are identical in all properties. To keep every object, including duplicates, use json(replace(concat(string(array1), string(array2)), '][', ',')).

7. How do I remove duplicate objects from an array?

Pass the array to union() with an empty array: union(variables('items'), json('[]')). Objects with the same properties and values count as duplicates, even if the property order differs.

🔸 #PowerPlatformTip 7: ‘UNION and FilterArray’ - the simpler union() route, for when duplicates should actually be removed.

🔸 #PowerPlatformTip 37: ‘Table to JSON’ - convert the merged array into JSON for easier downstream access.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.