Real-Time Power Automate Filter Array Examples

Real-Time Power Automate Filter Array Examples

No comments

Loading

In this Power Automate Filter Array tutorial, you will learn what a filter array data operation action is and how to use the filter array to filter your array collections efficiently.

Power Automate Filter Array Examples

In this section, we will understand the filter array in Power Automate with examples.

What is Power Automate Filter Array?

Filter Array is an action in Power Automate (formerly known as Microsoft Flow) that allows you to filter an array or a collection of items based on a specified condition. The action takes an array as input, applies a filter query to it, and returns a new array containing only the items that match the condition specified in the filter.

To use the Filter Array action, you need to specify the input array and the filter query. The filter query is a Boolean expression that evaluates each item in the array and returns true or false based on whether the item matches the specified condition.

The Filter Array action is useful when you need to work with specific items in an array, such as retrieving all items that meet certain criteria or removing items that do not meet specific conditions. By using Filter Array, you can streamline your workflows and automate repetitive tasks, such as processing data from different sources or filtering through large datasets to find specific information.

Examples: Power Automate Filter Array

Here are some examples of using the Filter Array action in Power Automate:

Power Automate Filter array with greater than expression

Suppose you have an array of objects, each with a “Name” and “Age” property, and you want to filter out all objects where the age is less than 18. You can use the Filter Array action to achieve this. Here’s how:

  1. Initialize an array of objects with “Name” and “Age” properties, for example:
Array collection example in Power Automate
Array collection example in Power Automate
[

 { "Name": "John", "Age": 25 },

 { "Name": "Mary", "Age": 17 },

 { "Name": "Bob", "Age": 21 },

 { "Name": "Sue", "Age": 16 }

 ]

 

2. Add the Filter Array action to your flow.

3. Set the From property to the array of objects you initialized in step 1.

Filter Array example in Power Automate with Greater Than Expression condition
Filter Array example in Power Automate with Greater Than Expression condition

4. In the Filter Query field, enter the following expression:

@greater(item()?['Age'], 18)

5. The output of the Filter Array action will be an array containing only the objects with an age greater than or equal to 18:

 [

 { 
"Name": "John", 
"Age": 25
 },

 { 
"Name": "Bob", 
"Age": 21
 }

 ]
Filter Array example in Power Automate with Greater Than Expression
Filter Array example in Power Automate with Greater Than Expression

Power Automate Filter array with greater than equal to expression

To get all people whose age is greater than or equal to 18, use the below expression:

@greaterOrEquals(item()?['Age'],18)

Power Automate Filter array with less than expression

To get all people whose age is less than 18, use the below expression:

@less(item()?['Age'],18)

Power Automate Filter array with less than equal to expression

To get all people whose age is less than or equal to 18, use the below expression:

@lessOrEquals(item()?['Age'],18)

Power Automate Filter array with contain expression

To get all people whose name contains letter ‘M’, use the below expression:

@contains(item()?['Name'], 'M')

Power Automate Filter array with contain expression
Power Automate Filter array with contain expression

Output: Power Automate Filter Array Output

Power Automate Filter array with contain expression output
Power Automate Filter array with contain expression output

Power Automate Filter array with AND and equals expression

To get all people whose department name is sales and age is 30, use the below expression:

@and(equals(item().Department, 'Sales'),equals(item().Age, 30))
Power Automate Filter array with AND and equals expression
Power Automate Filter array with AND and equals expression

Output: Power Automate Filter Array Output

Power Automate Filter array with AND and equals expression output
Power Automate Filter array with AND and equals expression output

Power Automate Filter Array Multiple conditions (with AND OR expression)

To get all people whose department is IT and whose age is 25 or all people from any department whose age is 21, use the below expression:

@or(and(equals(item().Department, 'IT'),equals(item().Age, 25)),equals(item().Age, 21))
Power Automate Filter array with AND OR expression
Power Automate Filter array with AND OR expression

Output: Power Automate Filter Array Output

Power Automate Filter array with AND OR expression output
Power Automate Filter array with AND OR expression output

Power Automate Filter array with Empty() equals expression

Let’s say we have an array of numbers from 1 to 8, and the eighth one is the empty string. We want to filter all numbers that are not empty.

Number Array example:

[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
""
]

To filter all numbers that are not empty, use the below expression:

@equals(empty(item()),false)
Power Automate Filter array with Empty equals expression
Power Automate Filter array with Empty equals expression

Output:

Power Automate Filter array with Empty equals expression output
Power Automate Filter array with Empty equals expression output

Filter Array With SharePoint List Items

Let’s say you have big data in a SharePoint list or document library where thousands of items are stored. And you want to Get Items OData filter query. Here in the OData filter query, we don’t have the leverage to pass all columns, so we can get all items using the Get Items pagination feature, and we can further refine the list items by the columns that we need in the filter array data operation action. This will improve the efficiency and speed of the execution of the query.

This is the Get Items action, which used to get all items from the SharePoint list.

Get Items action in Power Automate
Get Items action in Power Automate

Filter arrays with SharePoint list items: This is the filter array configuration for SharePoint list items from the above Get Items output. Here, we are filtering the Get-Items query output with the country list column, where we are getting all items where country is equal to Australia.

Filter Array with SharePoint list items
Filter Array with SharePoint list items

Now, if we click on the “edit in advanced mode” link, we can see the expression of mode this filter query.

Filter Array with SharePoint list items - filter query edit in advanced mode
Filter Array with SharePoint list items – filter query edit in advanced mode

Note:

  • In the above, “filed_1” is the internal name of the country column.
  • In all the examples above, we have used the “Edit in Advanced Mode” feature of the filter array action. In fact, we must use the “Edit in advanced mode” feature for the query expression.
  • For the Power Automate conditional trigger, we should use the filter array expression in advanced mode, then we can pass the expression to the trigger condition. This way, we can avoid the expression syntax error in the Power Automate conditional trigger.

Power Automate Filter Array: various conditional statements (expressions)

There are varieties of conditional statements (expressions) in the Power Automate Filter Array, such as:

  • contains
  • does not contain
  • is equal to
  • is not equal to
  • is greater than
  • is greater than or equal to
  • is less than
  • is less than or equal to
  • start with
  • does not start with
  • ends with
  • does not end with

 

Power Automate Filter Array various conditional statement (expression)
Power Automate Filter Array various conditional statement (expression)

We can see that using the above conditional statements or expressions, we can handle any type of business scenario to compare two strings.

Power automate get length of filter array

To get the length of the filter array output result, use the below expression in the compose data operation action:

Syntax:

length(body('Your_Filter_Array_Name'))

Example:

@{lenght(body(‘Filter_array_with_SharePoint_List_Items’))}

Power Automate Filter Array length expression
Power Automate Filter Array length expression

Output:

Power Automate Filter Array length output
Power Automate Filter Array length output

Note:

Summary: Filter Array Power Automate

Thus, in this article, we have learned about how to work with Power Automate Filter Array expression.

This article provides step-by-step instructions, screenshots, and explanations to help users understand how to use the Filter Array action in Power Automate. It also includes some examples of common scenarios where the Filter Array action can be useful, such as filtering SharePoint lists or Excel spreadsheets.

To conclude this article, the Power Automate Filter Array article is a helpful resource for anyone looking to learn more about using this feature in their Power Automate flow automation.

See Also: Other Power Automate Tutorials

You may also look into the below Power Automate Tutorials:

Are you preparing for a SharePoint job interview?

You can refer to these exclusive interview questions and answers that will help you get into your high-paying dream job:

Buy SharePoint Online eBook

Buy the premium version of SharePoint Online & Office 365 administration eBook from here:Buy SharePoint Online & Office 365 Administration eBook

If you would like to appreciate our efforts, please like our post and share it with your colleagues and friends. You may join the email list; it won’t spam you; it’s just notifications of new posts coming in, nothing else. 🙂

Loading

About Post Author

Do you have a better solution or question on this topic? Please leave a comment