How to Get Unique Values from an Array in Power Automate

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 remove duplicate values from your array in Power Automate.

Get Unique Values with the Union Function

["A","A","B","B","B","C","C"]

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 ["A","B","C"].

Here’s how you can get the unique values from your array.

  1. 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.

  1. Click into the input field so the dynamic content and expression builder will pop up.
  2. Click on the Expression tab.
  3. Add the union() function to the expression editor.
  1. Now click on the Dynamin content tab.
  2. Select the dynamic content for the array you want to return the set of unique values.
  3. Add a comma , to the expression to enter another argument in the union function.
  4. Select the same dynamic content for the array from step 6.
  5. 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.

Conclusions

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.

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

2 Comments

  1. Chris

    This is great, and, simple when you know how(!) – my question is, how do I achieve this when I want to turn multiple unique values (i.e. each pair of data that’s the same)?

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!