Usage of Union Function in Power Automate

Usage of Union Function in Power Automate

When working with arrays in Power Automate, you may need to combine multiple collections into a single array while removing duplicate values. The union() function provides an efficient way to achieve this without using loops or additional filtering actions.

The union() function merges two or more arrays and automatically returns only unique values, making it useful for data cleansing and collection management.

What is the Union Function?

The union() function combines arrays and removes duplicate entries.

union(
createArray('A','B','C'),
createArray('B','C','D')
)

Output:

['A','B','C','D']

Remove Duplicate Values from an Array

A popular trick is using the same array twice inside union() to remove duplicates.

union(
variables('Products'),
variables('Products')
)

This returns only unique values from the Products array.

Using Dynamic Arrays

You can merge arrays from SharePoint, Dataverse, Excel, APIs, or other connectors.

union(
variables('DepartmentList1'),
variables('DepartmentList2')
)

Output:

Unique values from both department arrays

Using Union with Multiple Arrays

The union() function can combine more than two arrays.

union(
variables('Array1'),
variables('Array2'),
variables('Array3')
)

This returns a single array containing only unique values from all arrays.

Important: The union() function removes duplicate values automatically. The returned array contains only distinct items.

Common Use Cases

Best Practices

Key Takeaways