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 arraysUsing 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
- Remove duplicate records
- Merge department lists
- Combine email recipients
- Aggregate data from multiple sources
- Prepare data for reporting
- Create unique collections
Best Practices
- Ensure inputs are arrays.
- Use union() instead of loops when possible.
- Validate output before processing.
- Use descriptive variable names.
- Test with large datasets.
Key Takeaways
- union() combines arrays into a single collection.
- Duplicate values are removed automatically.
- Can be used to clean and merge datasets.
- Works with dynamic content and variables.
- Simplifies array management in Power Automate.