Do you want to get the unique values from an array in your flow?
Getting the unique values in an array is a common request, but there is no action or function to get this done.
For example, you might have a list of email addresses, but you only want to get a list of unique values so you don’t send multiple emails to the same person.
Thankfully, it is still possible to get done! This post is going to show you how to get the unique values from your array in Power Automate.
Get Unique Values with the Union Function
This example shows an array created in a compose action. Your array might come from an external data source such as a SharePoint list, Excel, or the Dataverse, but the process will be the exact same for getting unique values.
The unique values from the above array will be
Here’s how you can get the unique values from your array.
- Add a Compose action to your flow. This is where you will use the expression to return the set of unique values.
It doesn’t necessarily need to be a Compose action and it can be in the action where you need to use unique values. But this is the best practice as it will allow you to reuse the results in multiple places.
- Click into the input field so the dynamic content and expression builder will pop up.
- Click on the Expression tab.
- Add the
union()function to the expression editor.
- Now click on the Dynamin content tab.
- Select the dynamic content for the array you want to return the set of unique values.
- Add a comma
,to the expression to enter another argument in the union function.
- Select the same dynamic content for the array from step 6.
- Press the OK button to enter the expression.
This creates a union of the array with itself.
The union function takes two or more arrays and then returns all the items from the arrays in a single array. A side effect of this is it will remove all the duplicate results from the result!
This means if you take the union of an array with itself, then you will remove all the duplicate values in the array and return only the distinct values.
Getting the unique values is a commonly requested task in Power Automate, but there is no action or function specifically for this.
The union function will remove duplicates and can be used to get unique values by taking the union of an array with itself.
Hope this helps! Let me know in the comments if you have any questions.