Remove duplicate values from an array using Power Automate Flow
Hello everyone!
In this blog, we will demonstrate how to schedule a flow that sends emails to all the owners of opportunities using Power Automate Flow.
Scheduled flows are the best option for actions that need to be automated on a schedule and will run at a specific time or date. For instance, using this approach, you might schedule a daily data upload to Dynamics 365 or SharePoint.
Use Case: Power Automate flow sends a reminder notification to the owners of Opportunities. To avoid multiple emails being sent to the same owner, we need to remove duplicate email addresses.
Step 1: Log in to the required Power Apps environment using URL make.powerapps.com by providing username and password, click on Create on the left-hand side as shown below, and click on Scheduled cloud Flow.
![](https://www.cloudfronts.com/wp-content/uploads/2023/01/image-7.png)
Step 2: Mention the date and time.
![](https://www.cloudfronts.com/wp-content/uploads/2023/01/image-8.png)
It will appear as this.
![](https://www.cloudfronts.com/wp-content/uploads/2023/01/image-9.png)
Step 3: Initialize a variable ‘Email_addresses’ of type Array which will store all the email addresses.
![](https://www.cloudfronts.com/wp-content/uploads/2023/01/image-10.png)
Step 4: Use List Rows to find the desired records from the required table. Select the table name. Also, I added the FetchXML code to fetch the required details of an entity.
![](https://www.cloudfronts.com/wp-content/uploads/2023/01/image-11.png)
Step 5: Add an ‘Apply to Each’ loop and insert the previous step’s value. This is done so that the value in every iteration is stored in the Array Variable. Add a step of ‘Set variable’ to store the email addresses in the Array.
![](https://www.cloudfronts.com/wp-content/uploads/2023/01/image-12.png)
Step 6: Add a new step ‘Compose’ and declare an empty array. This helps to save time when comparing with larger sets.
![](https://www.cloudfronts.com/wp-content/uploads/2023/01/image-13.png)
Step 7: Apply the Union function which removes duplicate values.
union(variables(‘Email_addresses’),outputs(‘Empty_Array’))
![](https://www.cloudfronts.com/wp-content/uploads/2023/01/image-14.png)
Step 8: Apply the Join function to extract the email addresses.
join(array(outputs(‘Union_function_to_remove_duplicate_mail_Values_in_Array’)),’,’)
Hope this helps!