Search techniques

  • Yellow belt
  • Standard
  • Tip 7

Remove duplicates with union()

Quiz question

What does union() return when you pass the same array twice?

Solution

  1. A) The array without duplicate entriesCorrect. union() returns each value only once, so union(x, x) works like DISTINCT.
  2. B) The array twice, one after the otherWrong. That would be simple concatenation. union() removes the duplicates.
  3. 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 Runs without a premium connector, so the license from Microsoft 365 is enough. Source on Microsoft Learn: Power Automate licensing FAQ. For your whole flow: License check.

Full tip on powerplatformtip.comPowerPlatformTip #7, with screenshots

Share

Short link: powerautomate.ninja/en/7

Source: PowerPlatformTip #7, Microsoft Learn: Reference for functions in workflow expressions.