How to Filter an Array by Multiple Conditions in Power Automate?

Nowadays, I am working with an array in Power Automate. So, doing a bit more research on this. In today’s tutorial, I will explain how to filter an array by multiple conditions in Power Automate. We will use the same filter array action in Power Automate.

Here, I will also show you two different examples:

  • Filter an Array by multiple conditions in a manually created array using Power Automate
  • Filter Excel items array by multiple conditions in Power Automate

Filter an Array by Multiple Conditions in Power Automate

For this example, we will manually create an array of objects and explore how to filter it with multiple conditions in Power Automate.

You can see below the Array of objects for ‘Employee Records’:

[
  {
    "Name": "Alice",
    "Department": "HR",
    "Status": "Active",
    "Email": "[email protected]",
    "Location": "New York"
  },
  {
    "Name": "Miriam",
    "Department": "Finance",
    "Status": "Inactive",
    "Email": "[email protected]",
    "Location": "Chicago"
  },
  {
    "Name": "Charlie",
    "Department": "IT",
    "Status": "Active",
    "Email": "[email protected]",
    "Location": "San Francisco"
  },
  {
    "Name": "Johanna",
    "Department": "IT",
    "Status": "Inactive",
    "Email": "[email protected]",
    "Location": "Boston"
  },
  {
    "Name": "Alex",
    "Department": "HR",
    "Status": "Active",
    "Email": "[email protected]",
    "Location": "Seattle"
  },
  {
    "Name": "Frank",
    "Department": "Marketing",
    "Status": "Active",
    "Email": "[email protected]",
    "Location": "Miami"
  }
]

Now, I want to filter the array mentioned above, based on multiple conditions that include:

  • Department = HR (or) IT
  • Status = Active
  • Location = New York
  • These three conditions should be satisfied by the and() function.

To filter this, we can use the Filter Array action in Power Automate. Follow the steps below.

  1. For this, I will create an Instant cloud flow in Power Automate. You can check out Instant Cloud Flow if you don’t know how to build flows in Power Automate.
  2. To set the Array values to a variable, add an ‘Initialize variable’ action. Enter the name for a variable, set Type as (Array), and Value with the array of objects placed in the above code.
Power Automate Filter Array multiple conditions
  1. Then, take a ‘Filter array’ action to filter the array values based on the given multiple conditions. Set parameters such as ‘From’ and ‘Filter Query’.
    • From: Choose a variable from the previous step. In my case, it is VarEmployeeRecords.
    • Filter Query: Click on Edit in Advanced mode option -> Insert the expression provided in the code below.
and(
  or(
    equals(item()?['Department'],'HR'),
    equals(item()?['Department'],'IT')
  ),
  equals(item()?['Status'],'Active'),
  equals(item()?['Location'],'New York')
)
Filter an Array by Multiple Conditions in Power Automate
  1. Following the previous step, I will add a ‘Compose’ action to display the filtered items. Include the body of the filter array action within the Inputs parameter.
Power Automate Filter Array multiple conditions equals

The flow is completed now. Click on the Save button to save the flow. Then, run it manually.

Output:

Filter Array multiple conditions equals Power Automate

Filter Excel Items Array by Multiple Conditions in Power Automate

Let me explain this example by referencing the Excel items array using the Power Automate Filter array action.

You can see the Excel sheet with the list of records in the screenshot below:

Power Automate Filter array multiple condition contains

From the list of items present in the Excel sheet, I wanted to filter the records that satisfy the following multiple conditions.

  • Designation contains Manager substring [OR] Experience >5 Years
  • Joining Date = Today’s Date
  • Location = Chicago
  • The four statements should be satisfied by the and() function.
  1. On the Power Automate canvas, add a ‘Manually trigger a flow’ trigger, which can be run by clicking a button.
  2. Then, to fetch the rows present in an Excel table, add the ‘List rows present in a table’ action. Set the required parameters.
    • Location: Select the SharePoint site address or OneDrive location where you stored the file.
    • Document Library: Choose the specific document library from the options.
    • File: Select the desired file.
    • Table: Choose the table from the drop-down options.
Power Automate Filter Array contains multiple values

Note:

The Excel stores dates in the integer format. While filtering the excel items based on the date column, first we need to convert the integer format into date format that Power Automate should recognise.
Expression to convert integer into date format:
addDays(’12/30/1899′, int(item()?[‘Joining Date’]), ‘yyyy-MM-dd’) – Replace Joining Date with your Excel column name.

  1. Next to that, take the ‘Filter Array’ action that filters the Excel items based on multiple conditions. Provide the following parameters.
    • From: Take body/value dynamic content from the filter array action.
    • Filter Query: Click on the Edit in advanced mode button -> Insert the expression placed below.
and(
  or(
    contains(item()?['Designation'], 'Manager'),
    greater(int(item()?['Experience']), 5)
  ),
  equals(
    addDays('12/30/1899', int(item()?['JoiningDate']), 'yyyy-MM-dd'),
    formatDateTime(utcNow(), 'yyyy-MM-dd')
  ),
  equals(item()?['Location'], 'Chicago')
)
Power Automate Filter array multiple conditions Excel
  1. In the final step, add a ‘Compose’ action to display the outputs from the previous step.
    • Inputs: Select Body(Filter Array) from dynamic content.
Filter array multiple conditions Excel in Power Automate

Save and run the flow.

Output:

  1. Have a look at the reference image, which shows the record that satisfies all the given conditions.
Filter array multiple conditions Excel Power Automate

You can also check the above details in the Excel sheet.

Power Automate Filter Excel array multiple condition

In this tutorial, you have learnt how to filter an array based on multiple conditions in Power Automate through two different examples.

I hope you found this article helpful and informative. Feel free to share your thoughts and feedback in the comments section below.

Power Automate Articles You May Read:

>

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…