Learn how to filter an array in Power Automate! In this article you will find simple and complex examples of using Power Automate Filter array action. We provide examples for the most common use cases.
Do you want filter items of a SharePoint list?
You used “Get items” action and want to limit the result to your filter? In this case you should take a look at OData filters before you go any further in this article. They are the better solution for your use case.
- Do you want filter items of a SharePoint list?
- Step by step: How do you filter an array in Power Automate? (Simple Example)
- Filter array examples
- 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
- Contains
- Does not contain
- Starts with
- Does not start with
- Ends with
- Does not end with
- Filter array of objects
- Multiple Conditions
- Filter array and
- Filter array or
- Filter array by date range
- Remove empty strings from array
- Filter array by column
- Filter array by another array
- Filter array unique values
- Filter array get first
- Filter array parse json
Step by step: How do you filter an array in Power Automate? (Simple Example)
We will define an array with numbers and filter the array for all numbers that are greater than 5. This is most simple example that come to my mind. The main goal in this step by step guide is to demonstrate how everything needs to be set up. Experienced readers can skip this section or use the table of contents to navigate to the part they are interested in.
Filter an array for all numbers greater than 5.
-
Create a new flow
My flows – New flow
-
Set name, select ‘Manually trigger a flow’ and click ‘Create’
Build an instant cloud flow
-
Click on ‘New step’
New step
-
Filter for ‘initi’ and select ‘Initialize variable’
Select action
-
Set Name, Type and Value of variable like shown below
Initialize array
-
Click on ‘New step’
New step
-
Filter for ‘filter’ and select ‘Filter array’
Filter array action
-
Click on Form: ‘Array to filter’ and click on ‘MyArray’
Filter array from
-
Click on text input ‘Choose a value’, click on ‘Expression’, enter ‘item()’ and click ‘OK’
Filter array value in condition
-
Select ‘is greater than’ from drop down and set value to ‘5’
Filter array greater than condition
-
Click on ‘Save’, wait a few seconds and click on ‘Test’
Save and Test
-
Select ‘Manually’ and click on ‘Test’
Start test
-
Click on ‘Run flow’
Run flow
-
Click on ‘Done’
Done
-
Check test result
Filter array output result
Filter array examples
Here you find a large collection of examples on how to filter an array with Power Automate. To focus on the described task, we do not provide a step-by-step guide for every use case. In case you are not sure how to set up the examples, follow the step-by-step guide at the beginning of the article. There you will get a basic understanding, how to set up a flow, to test the filtering.
Is equal to
See how to filter an array and collect all items that are equal to a given value. This example will return [7,7].
Is not equal to
See how to filter an array and collect all items that are not equal to a given value. This example will return [1,1,2,3,4,5,6,8].
Is greater than
See how to filter an array and collect all items that are greater than a given value. This example will return [8].
Is greater than or equal to
See how to filter an array and collect all items that are greater than or equal to a given value. This example will return [7,7,8].
Is less than
See how to filter an array and collect all items that are less or equal to a given value. This example will return [1,1,2,3,4,5,6].
Is less than or equal to
See how to filter an array and collect all items that are less or equal to a given value. This example will return [1,1,2,3,4,5,6,7,7].
Contains
A pretty common use case is to filter an array by checking whether a certain element or substring is within the array that needs to be filtered. In the simple example below, all elements containing an ‘a’ are passing the filter. For the concrete example below, the result is [“Paul”,”Sally”], since Peter does not contain an ‘a’.
Does not contain
To do the opposite of the contains comparison use the does not contain comparison.
Note: The does not contain condition is NOT case-sensitive. ‘Alfred’ for instance would not pass the filter.
Starts with
Filtering strings in array that start with a certain string can be achieved with starts with.
Note: The starts with condition is NOT case-sensitive. ‘sunday’ for instance would pass the filter.
Does not start with
Filtering strings in array that not start with a certain string can be achieved with does not start with.
Note: The starts with condition is NOT case-sensitive. ‘Achim’ for instance would pass not pass the filter.
Ends with
Filtering strings in array that end with a certain string can be achieved with ends with.
Note: The starts with condition is NOT case-sensitive. ‘ben smith’ for instance would pass the filter.
Does not end with
Filtering strings in array that not end with a certain string can be achieved with does not endwith.
Note: The starts with condition is NOT case-sensitive. ‘ben smith’ for instance would pass not pass the filter.
Filter array of objects
@greater(item()['Age'],40)
Multiple Conditions
In case you want a Power Automate Filter array with multiple conditions, you need to switch to advanced mode:
In the advanced mode you formulate more complex expressions. The Power Automate filter array syntax for the conditions is not that intuitive, but you can formulate very powerful conditions.
For instance you might want to filter a date or number range. You can achieve this by providing two conditions and combine them via and. See the example below:
The used expression in the Power Automate Filter array with multiple conditions example for copy and paste:
@and(greater(item(), 2),less(item(),5))
You can build very complex conditions by using:
- and
- or
- not
- () brackets
Filter array and
The and condition allows you to combine multiple conditions. For instance you can change for age ranges like this:
@and(greater(item()['Age'],19),less(item()['Age'],30))
Filter array or
The or condition allows you to combine multiple conditions. For instance you can change for age ranges like this:
@or(less(item()['Age'],19),greater(item()['Age'],30))
Filter array by date range
To filter by a date range you have to merge to two conditions with and. This example filters all Employees that were born in the 80ies.
@and(greaterOrEquals(formatDateTime(item()['BornAt'],'yyyy-MM-dd'),'1980-01-01'),less(formatDateTime(item()['BornAt'],'yyyy-MM-dd'),'1990-01-01'))
Remove empty strings from array
In case you want to remove empty strings from an array, you can use the following expression to filter empty strings:
@not(empty(item()))
Filter array by column
To filter by a certain column of your data, use the syntax item()[‘COLUMN_NAME’].
See the example below:
@greater(item()['Age'],40)
[
{
"Name": "John Doe",
"Age": 21
},
{
"Name": "Sally Smith",
"Age": 45
},
{
"Name": "Mike Miller",
"Age": 45
}
]
Filter array by another array
Filtering elements of one array by another array:
Filter array unique values
In case you want to remove duplicate entries of an array, so that every item is unique, you do not need to use the filter array action. A shorter way is to use an expression with union and passing the array to union twice. This way duplicate entries get removed. It is like a SQL distinct.
See the full expression for the example here:
union(variables('Numbers'),variables('Numbers'))
Filter array get first
Sometimes you are only interested in the first value returned by a filter. You can get items by index like this (0=first item):
body('Filter_array')[0]
Filter array parse json
Using the parse JSON action makes using the filter array action more intuitive, because you do not have to use the item() expression. For the example below, the schema was generated by the sample JSON.
[
{
"Name": "John Doe",
"Age": 21
},
{
"Name": "Sally Smith",
"Age": 45
},
{
"Name": "Mike Miller",
"Age": 45
}
]