How to Use Union Function in Power Automate
How to Use Union Function in Power Automate
Power Automate provides several powerful expression functions for working with arrays and collections. One of the most useful functions is union(), which allows you to combine multiple arrays while automatically removing duplicate values.
The union() function is commonly used for data cleansing, merging collections, generating unique recipient lists, and preparing data for reports and integrations.
What is the Union Function?
The union() function combines two or more arrays and returns only distinct values.
union(
createArray('A','B','C'),
createArray('B','C','D')
)
Output:
['A','B','C','D']Remove Duplicate Values
A common technique is using the same array twice inside union() to remove duplicates.
union(
variables('ProductList'),
variables('ProductList')
)
The output contains only unique values from the ProductList array.
Merge Dynamic Arrays
You can merge arrays retrieved from SharePoint, Dataverse, Excel, APIs, or other connectors.
union(
variables('DepartmentArray1'),
variables('DepartmentArray2')
)
This creates a single collection containing unique values from both arrays.
Combine Multiple Arrays
The union() function supports more than two arrays.
union(
variables('Array1'),
variables('Array2'),
variables('Array3')
)
The output contains unique values from all provided arrays.
Important: The union() function automatically removes duplicate values and returns only distinct items. All inputs must be arrays.Common Business Scenarios
- Combining email recipient lists
- Removing duplicate records
- Merging department collections
- Preparing reporting datasets
- Data migration projects
- API response consolidation
Benefits of Using Union()
- Eliminates duplicates automatically
- Reduces workflow complexity
- Improves performance
- Requires fewer actions
- Simplifies collection management
Best Practices
- Validate that inputs are arrays.
- Use descriptive variable names.
- Test output with large datasets.
- Document complex expressions.
- Use union() instead of loops where possible.
Key Takeaways
- union() merges multiple arrays into one collection.
- Duplicate values are removed automatically.
- Supports dynamic content and variables.
- Useful for data cleansing and collection management.
- Improves workflow efficiency and readability.