How To Use Power Automate Filter Array By 21+ Examples

Power Automate Filter Array

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.

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.

power-automate filter array

Filter an array for all numbers greater than 5.

  1. Create a new flow

    Power Automate Create Instant Cloud Flow

    My flows – New flow

  2. Set name, select ‘Manually trigger a flow’ and click ‘Create’

    Power Automate Build instant flow

    Build an instant cloud flow

  3. Click on ‘New step’

    Power Automate Add New step

    New step

  4. Filter for ‘initi’ and select ‘Initialize variable’

    Power Automate Initialize variable

    Select action

  5. Set Name, Type and Value of variable like shown below

    Power Automate Initialize Array

    Initialize array

  6. Click on ‘New step’

    Power Automate New Step

    New step

  7. Filter for ‘filter’ and select ‘Filter array’

    Power Automate Filter Array

    Filter array action

  8. Click on Form: ‘Array to filter’ and click on ‘MyArray’

    Power Automate Filter Array From

    Filter array from

  9. Click on text input ‘Choose a value’, click on ‘Expression’, enter ‘item()’ and click ‘OK’

    Power Automate Filter Array chose a value

    Filter array value in condition

  10. Select ‘is greater than’ from drop down and set value to ‘5’

    Power Automate Filter Array greater than 5

    Filter array greater than condition

  11. Click on ‘Save’, wait a few seconds and click on ‘Test’

    save and test

    Save and Test

  12. Select ‘Manually’ and click on ‘Test’

    test

    Start test

  13. Click on ‘Run flow’

    run flow

    Run flow

  14. Click on ‘Done’

    done

    Done

  15. Check test result

    test result power automate filter array

    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].

Power Automate filter array is equal to
Filter Array – is equal to

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].

Power Automate filter array is not equal to
Filter array – is not equal to

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].

Power Automate filter array is greater than
Filter array – is greater than

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].

Power Automate filter array is greater than or equal to
Filter array – is greater than or equal to

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].

Power Automate filter array is less than
Filter array – is less than

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].

Power Automate filter array is less than or equal to
Filter array – is less than or equal to

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’.

Power Automate Filter Array Contains
Filter Array – Contains

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.

Power Automate Filter Array Does Not Contain
Filter array – Does not contain

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.

Power Automate Filter Array starts with
Filter array starts with

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.

Power Automate does not start with
Filter Array – does not start with

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.

Power Automate Filter Array ends with
Filter array ends with

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.

Power Automate filter array does not end with
Filter Array – does not end with

Filter array of objects

@greater(item()['Age'],40)
Power Automate Filter array of objects
Power Automate – Filter array of objects

Multiple Conditions

In case you want a Power Automate Filter array with multiple conditions, you need to switch to advanced mode:

power automate filter array advanced mode
Filter array – Edit in 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:

Power Automate Filter Array Multipile Conditions
Power Automate Filter array – Multiple conditions

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))
Power Automate Filter array and
Filter array and condition

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))
Power Automate Filter array or
Filter array or condition

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'))
power automate Filter array by date range
Filter array by date range

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()))
Power Automate Filter array empty strings
Filter array – filter empty strings

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)
Power Automate Filter array by column
Filter Array by column
[
{
    "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:

power automate filter array based on 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.

Power Automate power automate filter array unique values
Remove duplicates

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]
Power Automate Filter array get first
Filter array get first

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
}
]
Power Automate Filter array parse json
Filter array parse json

Leave a Comment

Your email address will not be published. Required fields are marked *