How to filter array in Power automate flow

Hello everyone and welcome to my blog. Today’s blog will be on how to filter an array in Power Automate flow.

In this blog, we shall cover different scenarios for filter. Power Automate has native support for filtering arrays. You can use the Filter array action of the Data Operation control to filter any type of arrays.

Our first example is an Array with properties. Below is a sample JSON array with properties.

[
   {
      "Firstname": "Debajit",
      "Lastname": "Dutta",
      "ID": 123,
      "Category" :  "EMP"
   },
   {
      "Firstname": "John",
      "Lastname": "Doe",
      "ID": 456,
      "Category": "CONSULTANT"
   },
   {
      "Firstname": "Megan",
      "Lastname": "Campbell",
      "ID": 789,
      "Category": "EMP"
   }
]

I want to filter the items where Category is EMP. I use the ‘Filter Array’ action.

The formula expression is highlighted. I am using the item() construct to check for the category.

item()['Catgeory']

When I run the flow, I can now see only the items for which Category = EMP.

Well, that was simple. Let’s try an array with nested properties. Below is the array sample.

[
   {
      "Firstname": "Debajit",
      "Lastname": "Dutta",
      "Department": {
         "name": "HR",
         "code":  101
      },
      "Category" :  "EMP"
   },
   {
      "Firstname": "John",
      "Lastname": "Doe",
      "Department": {
         "name": "IT",
         "code": 102
      },
      "Category": "CONSULTANT"
   },
   {
      "Firstname": "Megan",
      "Lastname": "Campbell",
      "Department": {
         "name": "HR",
         "code": 101
      },
      "Category": "EMP"
   }
]

I need to filter all items where Department code is 101. To do this, I used the expression item()[‘Category’][‘code] .

How about simple array values and not objects? It’s actually very easy. We just need to use the item() expression to access each item of the array.

In the below sample, I am filtering array items which are not null. Check for filter where I am using the null expression to compare filter out null values.

If you have a requirement to filter null values from an array in Power Automate, you can try the above example.

Hope you liked this post. If this post has helped, you can buy me a coffee. Links on right pane.

For similar topics on Microsoft.NET and Power Platform, subscribe to my blog using the Subscribe option on right pane.

You will also like the below posts.

Debajit Dutta
Business Solutions MVP