How to remove duplicate items from an Array in Power Automate

Follow Debajit’s Power Apps & Dynamics 365 Blog on WordPress.com

I am back after sometime with another blog on Power Automate. And this time I am going to focus on a very important functionality – “Remove duplicate items from an Array“.

You have to agree with me on this – “Removing duplicate items from an array” is something we do every now and then when we design applications. And more often than not every framework has few functions up it’s sleeve to perform that.

Whenever we think of such functionality, the first function that come to our mind is the Distinct() function or something similar on those lines. And when I had a similar requirement in Power Automate, I too thought the same. There must be a function like Distinct() or Unique() which would return me a an array without the duplicate values.

I have an excel which shows the list of computer devices by manufacturer. The excel file is uploaded in onedrive for business.

I call a flow from Power App and when I pass in the manufacturer name, it should return the available device types for that manufacturer. Quite a easy configuration to be honest.

filter duplicate from array in Power Automate

Basically I am getting the excel file from one-drive and then filter out the devices based on the manufacturer. And then I am iterating through the items and adding the device type to the array variable.

However the issue with it is the Device types are repeated in the Array variable. The array now contains duplicate device type values.

Surprisingly there is no distinct() function to remove the duplicates. We have to use the union() function to remove the duplicates. Below is the expression to do the same.

union(variables('AvailableDeviceTypes'),variables('AvailableDeviceTypes'))

Here AvailableDeviceTypes is my array variable. union() function requires two array variables. Since I need to remove the duplicates from a single array, I pass the same array variable twice.

And voila! All my duplicates are removed from the array.

Hope this helped!

You may also like the below posts

Debajit Dutta
Business Solutions MVP