Data Flow with Array Filtering in Power Automate - CloudFronts

Data Flow with Array Filtering in Power Automate

When working with arrays in Power Automate, it’s common to need to filter or select a specific item based on certain attributes. Whether you’re handling JSON data from an API, processing records from a list, or managing dynamic content within a flow, efficiently identifying the right item is key.

In this blog, we’ll explore a simple yet effective method to extract the desired item from an array using expressions in Power Automate. By the end, you’ll have a clear strategy to streamline your workflows and enhance the intelligence of your automation.

In case you need to select an item from an array in Power Automate based on the value of a certain attribute, here’s how you can do it.

Scenario

You have an array of objects, and each object has a specific attribute. You want to efficiently select the object(s) where this attribute matches a particular value.

As you see, the array of objects have different structure – All of them have an attribute called “key” and that’s the one you want to select and then process further.

Let’s see how we do it.

Filter Array

Let’s see how you can select the item from the array based on the value of the “key” attribute instead of looping through all the items and matching.

  1. Ensure the array of objects is stored in a variable within your Power Automate flow – Filter Array Action.
  2. In Data Operations connector, you’ll find the Filter Array action which we’ll need to pick the item with “key” = “RelatedEntities”
  3. In Filter Array, you set the Input to the array data which is stored in the variable shown above.
  4. Once you select, you then need to provide the condition to filter the Array.
    In this example, we want to filter based on the “key” = “RelatedEntities” as seen in the Scenario section above.
    So, in the dynamic content section, go to Expression section and then use item() function and just like you access an element in a JS, you can mention what attribute you are trying to access.
  5. And in the value, you can mention what the value has to be.
  6. And in the answer, when you run the Flow with the sample data, you’ll get the below result.
  7. The other elements are filtered out. If you have two items of the same value, both will be returned.
  8. Below is how the actual code looks like when you edit in Advanced Mode –

To encapsulate, by using this approach, you can efficiently select specific items from an array based on the value of a particular attribute, making your Power Automate flows more dynamic and tailored to your specific needs.

We hope you found this blog useful, and if you would like to discuss anything, you can reach out to us at transform@cloudfonts.com.


Share Story :

SEARCH BLOGS :

FOLLOW CLOUDFRONTS BLOG :


Secured By miniOrange