The Power Automate Union function collects all elements of multiple collections and merges them into one collection without duplicate entries.
In case you want to create a collection containing only of elements that are present in both collection, take look at the Power Automate intersection function.
In this article, I’ll introduce you to the union function and will provide a step-by-step guide on how to use the function in a Microsoft flow.
Power Automate Union Function
Return a collection containing all elements present in any of the specified collections. If multiple items have the same name, the one that appears last in the input collections will be included in the result.
union('<collection1>', '<collection2>', ...) union([<collection1>], [<collection2>], ...)
- collection1 (mandatory): The first collection from where you want all the items in the result.
- collection2 (mandatory): The second collection from where you want all the items in the result.
- collection3 ..
- Returns a collection: An aggregation that encompasses every item from the designated collections without duplicates.
Power Automate Union Expression Example
Power Automate union two arrays
The most obvious example for the union function is two use it with two arrays:
union(createArray(1,2),createArray(2,3)) => [1,2,3]
Power Automate union distinct
The union function can be used as a distinct function. We only need to pass the collection twice for which we want unique values
// array variable 'myArray' = [1,1,2,2,2,3,3] union(variables('myArray'),variables('myArray')) => [1,2,3]
How To Use The Power Automate Union Function
Follow the steps to use the Power Automate Union function in a flow.
Create a new flow with trigger ‘Manually trigger a flow’
Add a new step by clicking on ‘+ New step’
Add a new step
Search for ‘initialize’ and click on ‘Initialize variable’
Add Initialize variable action
Setup Initialize variable: 1) Provide a name, 2) select type Array, 3) Set value to ‘[1,2,3]’
Add a compose step by searching for ‘compose’ and clicking on ‘Compose’
Add Compose action
Setup compose action: 1) click into Inputs (popup appears), 2) click on ‘Expressions’, 3) set expression to ‘union(variables(‘collection1’),createArray(3,4,5))’ 4) click on ‘OK’
Setup union expression in Power Automate
Save and do a test run
Result test run – Power Automate union function example