Removing duplicate values from arrays is a common task when building automated workflows in Power Automate. Duplicates can clutter your data and cause unnecessary repetition in actions such as sending emails, creating records, or looping through values.
Why use union() to Remove Duplicates in Power Automate?
The union() function is one of the most efficient and elegant ways to remove duplicates from arrays in Power Automate especially for arrays containing primitive values like strings or numbers.
Supported Input Types for Array De-duplication
Before we dive into the flow, it’s important to know what kinds of data this method supports. You can remove duplicates from:
🔹 1. Arrays of Primitive Values
1. Strings: ["apple", "banana", "apple"]
2. Numbers: [1, 2, 3, 1, 2]
🔹 2. Arrays of Objects (Advanced Use)
- Objects: [{“name”: “John”, “id”: “123”},
{“name”: “John”, “id”: “123”},
{“name”: “Doe”, “id”: “124”},]
Why It Works Well
1. No need for loops or conditions: union() handles deduplication internally without extra action.
2. Optimized for performance: It’s processed directly in Power Automate expression engine.
3. Simplifies your flow: Keeps your logic short and readable, even for beginners.
When union() Won’t Work as Expected
While union() is great for most use cases, there are some limitations:
Scenario
Limitation
Array of objects
It checks for complete object equality. If objects have the same values but different property orders or extra fields, they may not be treated as duplicates.
Case sensitivity
union() is case-sensitive. "Apple" and "apple" will be treated differently.
Whitespace differences
"value " and "value" are also seen as distinct values.
Workaround for objects: If you only care about a specific property (e.g., email or id), you can first use the select() action to extract that field into a simpler array before applying union().
Step-by-Step Guide to Remove Duplicates from an Array in Power Automate
Let’s build a simple flow that removes duplicates from an array.
🔹 Step 1: Create a New Flow
1. Go to Power Automate.
2. Click Create > Instant cloud flow.
3. Choose the Manually trigger a flow option.
4. Click Create.
🔹 Step 2: Initialize an Array Variable
1. Add the Initialize variable action.
2. Set the properties:
a. Name: inputArray
b. Type: Array
c. Value: ["apple", "banana", "apple", "orange", "banana"]
🔹 Step 3: Remove Duplicates Using union() Expression
1. Add the Compose action.
2. Set the Inputs to this expression:
Inputs: union(variables('inputArray'), variables('inputArray'))
🔹 Step 4: Run the Flow
1. Run the flow by clicking the Test button.
🔹 Final Output
Conclusion:
Now you know how to remove duplicate values from an array in Power Automate using a simple trick with the union() function. This technique helps you clean your data, simplify your flows, and avoid unnecessary repetition or errors.
Whether you're processing form responses, Excel data, or dynamic content, removing duplicates ensures your automation remains fast, efficient, and reliable.