Power Up Your Automations: Mastering Array and Object Comparison in Power Automate

Introduction

In Power Automate, we may often need to compare arrays, whether to find similar elements or eliminate duplicate items. Rather than using the 'Apply to each' step, which can increase processing time, we can use expressions to achieve the same result.

This article will explore the intersection and union expressions in Power Automate and how to incorporate them to reduce processing time.

Intersection in Power Automate

A workflow function called 'intersection' in Power Automate helps us extract similar elements in arrays.

syntax : intersection([<collection1>], [<collection2>], ...)

Suppose we have two arrays, Array1 and Array2, with the respective data [1,2,3,4,5] and [2,3,6,7,5]. If we compare these arrays, the resulting array will only contain the elements present in both arrays, which are 2, 3, and 5.

We can also perform a similar comparison on the objects, considering we have two objects, Object1 with data as { <"Name": "John", "Age": 25, "Place": "ABC" } and Object2 with data as { "Name": "Spark", "Age": 25, "Place": "ABC" }

the result would be { "Age": 25, "Place": "ABC" }

for more information related to the intersection workflow function, please click here.

Union in Power Automate

Another useful workflow function in Power Automate is "union," which enables us to remove duplicates from arrays without requiring a time-consuming comparison process using "apply to each." Using "union" can simplify the process and achieve the same outcome more efficiently.

Syntax : union('<collection1>', '<collection2>', ...)

Consider we have two arrays, Array1 and Array2.

Array1 = [1,2,3] 
Array2 = [1, 2, 10, 101]

union(Array1,Array2) = [1,2,3,10,101]

For more information related to the union workflow function, please click here.

Summary

Ready to take your Power Automate skills to the next level? With these array and object comparison tips, you'll be well-equipped to streamline your workflow and increase productivity like never before. Give them a try and see the difference for yourself!


Similar Articles