How to Use Filter Array in Power Automate?

Recently, I worked on a Power Automate flow that required sending a report to a manager on a monthly basis. The report should only include items with the status “New” from a SharePoint list. To do this, I used the Filter Array action in Power Automate.

The Filter Array action in Power Automate is particularly useful when working with large sets of data. It helps to select only the items that match a certain condition and ignore the rest. You can use this action to filter values from SharePoint, arrays, Excel, or other data sources in Power Automate.

In this tutorial, I will explain how to use the Filter Array action in Power Automate step by step. You will learn:

  • What is the Filter Array action in Power Automate
  • How to filter an array variable in Power Automate
  • How to filter SharePoint list items in Power Automate

Filter Array in Power Automate

  • The filter array action in Power Automate is a type of data operation that works on the entire array or a collection.
  • The filter array is specially used to filter an array of records based on a condition. We can also filter based on multiple conditions using the Advanced Mode Editor option.
  • The filter array will function in such a way that it filters and reduces the number of objects present in the array based on the provided filter condition, and returns the objects that match the condition.

Parameters:

  • From: Provide the array input here.
  • Filter Query: You can provide the condition.

Note

  1. We can not use the filter array action to change the shape of objects in array.
  2. The filtering is based on the case sensitive.
Power Automate Filter Array

Check out Filter Array in Power Automate Examples

Filter Items in an Array Variable Using Power Automate

For this example, you have an array of customer records with different country names.

[
  {
    "Name": "Thomas Edison",
    "Country": "USA"
  },
  {
    "Name": "Priya Shah",
    "Country": "India"
  },
  {
    "Name": "Leila Bouazizi",
    "Country": "Tunisia"
  },
  {
    "Name": "Johan vander",
    "Country": "USA,India"
  },
  {
    "Name": "Johan vander",
    "Country": "Africa"
  }
]

You want to filter this array in Power Automate only to retrieve customers from India or the USA.

To do this, follow the steps below:

  1. Open the Power Automate Home page, click on +Create -> Select Instant cloud flow -> Provide a flow name, choose to add Manually trigger a flow, and click on the Create button.
  2. After that, add an “Initialize variable” action to set the array value. Provide the parameters, such as Name, Type (set to Array), and Value, with an array of objects, as shown in the screenshot below.
Power Automate Filter Array example
  1. Add a “Compose” action and set the Inputs value to the strings [USA, India], as I want to filter the array items that contain these values. You can also rename the action. I have renamed it to VarCountries.
Power Automate Filter array dynamic conditions

Now, let’s filter the array based on this condition.

  1. To filter the array values, add a “Filter Array” action. Set the required properties:
    • From: Select Initialize variable [VarCustomerRecords] from dynamic content
    • Filter Query: Map the below values.
Choose valueOperatorChoose value
@{outputs(‘Compose’)}contains@{item()?[‘Country’]}
Filter Array in Power Automate

Now, the flow is ready. Save and test it manually.

  1. Once the flow runs successfully, you can open the Filter array outputs to see the result. The output array shows only the items that contain the Country value as ‘USA’ or ‘India’.

Output:

Power Automate Filter Array variable

This way, you can use the Filter Array action in Power Automate to extract only the items that meet your condition from an array.

Filter Array Based on a SharePoint List Item in Power Automate

To explain this, I will take one of the SharePoint lists named ‘Project Timeline’. This list has various types of records with Project status values. I want to filter the SharePoint list items that have a Project status value of New.

Power Automate Filter Array Single Value

Check out the steps below:

  1. Create a Power Automate Instant cloud flow that can be triggered by a single button click.
  2. Next, add an “Initialize variable” action to store the empty value. Provide a name for the variable and set the type to Array.
Filter array Power Automate
  1. To fetch the SharePoint list items, add a “Get items” action. Provide the site address and list name.
Power Automate array filter items
  1. To filter the SharePoint list items that have Project Status as New, add a “Filter Array” action. Set the parameters:
    • From: Provide body/value of get items from dynamic content.
    • Filter Query: Insert the code below.
@{item()?['ProjectStatus/Value']} is equal to New

If you have a different column name, you can replace the expression with your SharePoint column.

Power Automate filter array condition
  1. Then, add Apply to each loop, and select an output from previous steps to: body(‘Filter_array’).
Microsoft Power Automate Filter Array variable
  1. Inside the loop, add the “Append to array variable” action. This is because it will add items with a Project Status of ‘New’ to a variable.
    • Name: Select Initialize Array variable [varNewProjects] from the drop-down.
    • Value: Insert the below values.
{
  "Project Title": "@{item()?['Title']}",
  "Project Status": "@{item()?['ProjectStatus/Value']}",
  "Project Start Date": "@{item()?['ProjectStartDate']}",
  "Project End Date": "@{item()?['ProjectEndDate']}"
}
Power Automate filter array output
  1. To view the retrieved output, take a “Compose” action. In the Inputs parameter, select the Initialize variable.
How to use Filter Array Power Automate

Now that the flow is ready, save and test it by clicking the Test icon.

Output:

  1. Open the Compose Outputs. As you can see, the array of SharePoint items has a Project Status of New.
Power Automate Filter Array SharePoint list

This is how to work with the Filter array action in Power Automate.

You can use the Filter array & Get Items action to filter the SharePoint list of records or objects based on specific criteria. I have used both in many Power Automate flows.

Do let me know if you have any questions or suggestions in the comments section.

Also, you may read the following tutorials:

  • Hello Bijay,

    this

    @and(equals(item().Department, ‘Finance’),equals(item().Age, ’38’))

    didn’t work for me.

    This

    @and(equals(item()?[‘Department’], ‘Finance’),equals(item()?[‘Age’], 38))

    was much better 🙂

  • >

    Build a High-Performance Project Management Site in SharePoint Online

    User registration Power Apps canvas app

    DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

    Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

    Power Platform Tutorial FREE PDF Download

    FREE Power Platform Tutorial PDF

    Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…