3 min readRishi

Remove Duplicates From Arrays in Power Automate — 3 Approaches

In this series: Power Automate gotchas

Power Automate still does not have a built-in "Remove Duplicates" action. Here are three reliable approaches, from simplest to most flexible.

Approach 1: Union with Itself

The simplest one-liner. The union() function returns distinct values:

@union(variables('myArray'), variables('myArray'))

This works for arrays of simple values (strings, numbers). It compares values directly and removes duplicates. It does not dedupe objects by a key. Two records with the same email and different names are different JSON values, so union() keeps both. Use Approach 2 for that.

Example:

Input: ["apple", "banana", "apple", "cherry", "banana"]

Expression: @union(variables('myArray'), variables('myArray'))

Output: ["apple", "banana", "cherry"]

Use a Compose action with this expression, and you have your deduplicated array in one step.

Approach 2: Select + Union for Object Arrays

When dealing with arrays of objects and you want to deduplicate based on a specific property:

  1. Select — extract the key field into a simple array:

    @item()?['email']
    
  2. Compose — deduplicate with union:

    @union(body('Select'), body('Select'))
    
  3. Filter array — filter the original array to keep only the first occurrence of each key:

    @equals(
      indexOf(outputs('Compose_Unique_Keys'), item()?['email']),
      indexOf(outputs('Compose_Unique_Keys'), item()?['email'])
    )
    

Wait — that always returns true. The trick is slightly different. Use a Select on the unique keys and for each key, use first(filter(...)) to grab the first matching object:

@first(filter(variables('myArray'), item()?['email'], items('Apply_to_each')))

Approach 3: XPath for Complex Deduplication

For more complex scenarios, convert to XML and use XPath's distinct-values:

  1. Compose — convert array to XML:

    @xml(json(concat('{"root":{"item":', string(variables('myArray')), '}}')))`
    
  2. Compose — apply XPath:

    @xpath(xml(outputs('Compose_XML')), '//item[not(. = preceding-sibling::item)]')
    

This is more verbose but handles edge cases that union() doesn't cover.

Which Should You Use?

ScenarioApproach
Simple string/number arraysunion() — one expression
Object arrays, deduplicate by keySelect + Union + Filter
Complex nested deduplicationXPath
Performance critical (1000+ items)union() or move to a child flow with chunking

Performance Note

For arrays with more than a few hundred items, union() is still the right first tool. Above a few thousand objects, Apply to each plus Filter becomes the bottleneck — not the expression.

In that case:

  • Deduplicate in Dataverse or SQL (distinct, a view, or an alternate key upsert) before the flow sees the array
  • Process in batches with a child flow if you must stay in Power Automate
  • Move heavy transforms to an Azure Function or a Dataverse plugin if the array is a standing integration, not a one-off

Do not add a fourth Apply to each to "make union work on objects." That is how 20-second flows become 20-minute flows.

Key Takeaway

Start with union(array, array) — it solves 80% of deduplication needs in a single expression. Only reach for more complex approaches when you are working with object arrays or need key-based deduplication.

Keep reading

Newsletter

New posts, straight to your inbox

One email per post. No spam, no tracking pixels, unsubscribe anytime.

Comments

  • No comments yet. Be the first.