Remove duplicates with union()
Quiz question
What does union() return when you pass the same array twice?
Solution
- A) The array without duplicate entriesCorrect. union() returns each value only once, so union(x, x) works like DISTINCT.
- B) The array twice, one after the otherWrong. That would be simple concatenation. union() removes the duplicates.
- C) Only the entries that appear twiceWrong. union() combines the arrays and keeps each value once, including those that appear only once.
What it is about
When you merge data from two sources, duplicate entries quickly end up in the result. The union() function combines two arrays and returns each value only once. That leads to a simple trick: pass the same array twice, union(x, x), and you get the array back without duplicates, like DISTINCT in a database. This works with simple values and with objects. Then you narrow the result down with Filter array to the entries you need. Two built-in steps replace a loop with a condition and a variable. If you need to keep the duplicates, union() is the wrong choice.
The expression from the tip
union(x, x)When to use it, when not
Use it
When you merge lists or want to clean up an array before you continue.
Better not
When duplicate entries must be kept, for example bookings with the same amount.
Most common mistake
Removing duplicates in a loop with a condition and a variable, although a single expression is enough.
License
Standard This technique uses standard connectors. Microsoft 365 usage rights cover standard connectors. Check the rights for your whole flow. Source on Microsoft Learn: Power Automate licensing FAQ. For your whole flow: License check.
Share
Short link: powerautomate.ninja/en/7
Source: PowerPlatformTip #7, Microsoft Learn: Reference for functions in workflow expressions.
Prefer to continue with guidance? The Power Automate live course (in German) at the Power Platform Academy runs over four weeks. The next dates are not set yet, you can join the waiting list on the course page.