How to Filter an Array by String Values in Power Automate?

Recently, I was working on a Power Apps application named Expense Claims App. I had a requirement to create a Power Automate flow that filters files in a SharePoint document library containing a specific substring.

For example, if the file name is “Customer Invoice Details.docx”. I wanted to filter based on a substring, i.e, “Invoice”.

I achieved this with the help of the “Filter Array” action in Power Automate.

In this tutorial, I will cover how to filter an array by string values using the Filter Array action in Power Automate.

With this, I will also show you a few more examples, such as:

  • Filter Array by String Value using Power Automate
  • Filter a SharePoint Files Array by a Substring in Power Automate
  • Filter Empty Strings from SharePoint List Items Array using Power Automate Filter Array Action

Filter an Array by String Value using Filter Array Action in Power Automate

Let me give an example of how to filter an array by string values in Power Automate.

Here, I have created an Array of Objects, as placed in the code:

[
  {
    "invoiceId": "INV-101",
    "status": "Paid",
    "isOverdue": "false",
    "customer": {
      "name": "Daniel Craig",
      "email": "[email protected]"
    }
  },
  {
    "invoiceId": "INV-102",
    "status": "Pending",
    "isOverdue": "true",
    "customer": {
      "name": "Sana Ahmed",
      "email": "[email protected]"
    }
  },
  {
    "invoiceId": "INV-103",
    "status": "Overdue",
    "isOverdue": "true",
    "customer": {
      "name": "Thomas Lee",
      "email": "[email protected]"
    }
  }
]

Now, I want to filter the array present in the code above based on a string, specifically isOverdue‘, with a value of ‘false‘.

To achieve this, follow the steps below:

  1. Firstly, create an Instant cloud flow in Power Automate. If you’re a beginner, consider exploring the Power Automate button flow.
  2. To store the array value, add an “Initialize variable” flow action. Name the variable, set the type as ‘Array’, and put the Value with the Array provided in the code.
Power Automate Filter Array of Strings
  1. Next, add a ‘Filter Array‘ action to filter the array items with the ‘isOverdue‘ value as ‘false‘. Provide the parameters mentioned.
    • From: Take the Initialize variable from the previous step.
    • Filter Query: Insert the expression provided in the code below.
@{item()?['isOverdue']} is equal to @{string('false')}
Filter an Array by String Values in Power Automate
  1. To view the output from the previous step, take a ‘Compose’ action. Set the input parameters with a dynamic content of ‘Body‘ value coming from the Filter Array action.
Filter array string value Power Automate
  1. The flow is ready now. Save and test the flow manually. When the flow executes successfully, open and see the compose outputs. Have a look at the reference image, where it displays the Array object that has [isOverdue value: false].
Filter array string in Power Automate

This is how to filter an array based on a string value using the Filter Array action in Power Automate.

Filter SharePoint Files by Substring using Power Automate Filter Array Action

In this example, I took a SharePoint document library named ‘Invoice Documents‘, which contains various types of files such as .pdf, .xlsx, .docx, and more.

Power Automate Filter array contains string

Now, let’s see how to use the Filter Array action in Power Automate to retrieve only the files that contain the word ‘Invoice’ in their file names.

Check out the steps below:

  1. Create a Button flow in Power Automate so that a single button can trigger a click.
  2. To get the files from the SharePoint document library, add a ‘Get files (properties only)‘ action. Provide Site Address & List Name.
Filter array contains string Power Automate
  1. Then, add a “Filter Array” action to filter the filenames that contain a specific substring. Set the Parameters as shown below.
    • From: Take the body/value of a Get files action from the dynamic content.
    • Filter Query: Check the table below for the filter query.
Choose ValueOperatorChoose Value
@{item()?[‘{Name}’]}ContainsInvoice
Filter array contains substring Power Automate

Now, the filter array action will filter the array based on the given filter query. Filter Array outputs will show all the file properties. To display only the file names from the retrieved output, add the steps below.

  1. After that, add an ‘Initialize variable‘ action with an empty array, as shown in the screenshot.
Power Automate Filter array contains substring
  1. Following that, add an “Apply to each loop” action by selecting an output from the previous steps: Body of Filter Array action.
Microsoft Power Automate Filter array contains substring
  1. To append the file names to the empty array, add the “Append to array” variable action inside the loop. Set the required parameters.
    • Name: Select a variable from the drop-down. In my case, it is VarFiles.
    • Value: Insert the below code.
{
  "File Name": "@{item()?['{Name}']}"
}
Power Automate Filter Array SubString
  1. In the final step, take a Compose action to show only the File Names that contain the Invoice substring.
    • Inputs: Add the Initialize variable from the dynamic content [VarFiles].
Filtering Array with string in Power Automate

The flow is ready. Save and test it.

Output:

  1. Open and see the Compose action outputs. Refer to the image below that shows File names that contain the ‘Invoice’ string.
Microsoft Power Automate Filter Array contains string

This is how to filter an array of values that contain a specific substring using Power Automate from a SharePoint library.

Check out How to Filter an Array by Date in Power Automate?

Filter Empty Strings from SharePoint List Items using Power Automate [Filter Array Action]

Let me explain this example: filtering an empty string value from an array of SharePoint list items.

This is the SharePoint list, Invoice Tracker, with various types of columns.

Power Automate Filter Array by Empty String

In this example, I will filter the SharePoint list items Array where the “Invoice Number” and “Customer Email” columns have empty string values.

Do follow the steps to filter the SharePoint List Items Array:

  1. For this, I will create a manually triggered flow in Power Automate.
  2. To retrieve items from a SharePoint list, add a “Get items” action. Set the required parameters, such as Site Address and List Name.
Power Automate Filter array empty string
  1. Following the previous step, take a ‘Filter Array’ action to filter the SharePoint list items with empty strings from the [Invoice Number and Customer Email columns].
    • From: Select body/value of the Get items action from the dynamic content.
    • Filter Query: Click on Edit in advanced mode -> Insert the expression placed below.
or(empty(item()?['InvoiceNumber']),empty(item()?['CustomerEmail']))
Filter array empty string in Power Automate
  1. After that, I will create a table with the filtered SharePoint list items. To do that, add ‘Create HTML table‘ action. Set the parameters.
    • From: Select Body of Filter Array from dynamic content.
    • Columns: Choose the Custom option.
HeaderValue
Item Name@{item()?[‘Title’]}
Invoice Number@{item()?[‘InvoiceNumber’]}
Customer Email@{item()?[‘CustomerEmail’]}
Unit Price@{item()?[‘UnitPrice’]}

From the Values mentioned in the above table, replace the SharePoint column name with your list column name.

Filter array empty string using Power Automate
  1. In the last step, add a ‘Send an email (V2) ‘ action to send a table with SharePoint list items that contain empty strings. Configure the parameters, such as To, Subject, and Body.
Power Automate Filter Array of Empty Strings

The flow is completed now. Before running the flow, save it by clicking on the Save icon.

Output:

Filter an array empty string Power Automate

This way, you can filter an array of SharePoint list items by empty strings using Power Automate.

In this tutorial, I explained how to filter an array by string values in Power Automate using three different examples.

I hope you found this article interesting and helpful. You can also suggest your thoughts and comments in the comments section.

Also read other Power Automate Tutorials:

>

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…