Create and Filter an array in 2 easy steps

Filter an array or collection in Power Automate

When you want to filter an array in a Power Automate flow, there are a couple of  challenges you might face.

Other array operations

A while back wrote a post about arrays in Flow. One of the things that I didn’t look at was filtering arrays. Filtering arrays is actually really simple.

Power Automate has filter options available to make things easy. Before I filter an array I will first create an array.

Create an array

I started by creating an array. The array starts with [ and it ends with ] and each item inside the array starts with { and ends with }. All standard json stuff.

An Array in Power Automate

You could of course also use a compose action instead of this but it doesn’t matter too much.

You might also have an action that generates an array and you haven’t got any option to specify filters on the action and the action returns too much information.

Filter Array or Collection

Now I only want to select the items that have IsOk set to Yes. This can be done with the Filter array action.

Filter the Array in Microsoft Flow

The filter array’s condition can be set in the advanced mode to

@equals(item()?['IsOk'], 'Yes')

Or you could set the left hand side of the condition to item()?[‘IsOk’] using the expression editor and then set the right hand side to Yes.

The conditions here could include any kind of query that you would also use in conditions in your flow. So if you want to filter an array in you Power Automate flow, using the Filter action and set your condition.

Power Automate is sometimes just that simple!

17 thoughts on “Filter an array or collection in Power Automate

  1. I’m trying to pull multiple lines of data from an excel spreadsheet into a word template using MS Flow. Would an array work to pull the information.

  2. Can you please help me? I have a string in Logic Apps which is 40 chars long and I need to trucate it to 30. I don’t see a function like that and I have googled for hours. If you have any suggestions please let me know. Thanks! MIke Kiser

  3. Every day you make my day! Thank you very much for your help with Power Automate! It’s a great tool, but sometimes simple tasks become nightmares in Power Automate.

  4. Hi, I’ve used your posts quite a few times, so thanks. My current problem is that I cannot get a Power Automate Filter Array action to work with a Contains operator applied to an array obtained by a Get Items action. The column I’m trying the filter on is a multivalued choice column. Please have you come across any problems doing this?
    Regards, Stan.

    1. Hi Stan,

      Multi select choice fields or multi select people fields can indeed be complicated. You might have to push the records through a Select action and using this action reshape the data a bit to make the filtering easier.

  5. I need to compare two arrays that are similar but not column by column the same (one has more columns than the other); two array elements would be equal if three columns have the same value. I know this works: Filter array A, B contains items() would give me all elements that are the same while not contains would give me items in A not in B.

    Is there a way to create arrays from arrays just with a some columns? If I can do that, then I can reduce the arrays from Get rows/Get items to just what I want to compare.

    Even better would be a way to Filter array using the three columns. I have tried

    @and(equals(outputs(‘get_rows’)?[‘col1’],outputs(‘get_items’)?[‘col1’],
    (outputs(‘get_rows’)?'[‘col2’],outputs(‘get_items’)?[‘col2’],
    (outputs(‘get_rows’)?[‘col3’],outputs(‘get_items’)?[‘col3’]))

    But that gives me an error when I try to save the step.

    Questions, then:

    1. Can Filter array allow selection on multiple columns, and if so, what is wrong with my expression?
    2. Can I create arrays from the arrays resulting from the Get rows (SQL) and Get items (SharePoint) arrays that contains just some columns so I can compare elements in Filter Array?

    My strong preference is solving #1.

    By the way, I have made a number of attempts tackling this with Apply to each, but that swells and swells with nested Apply to each as I create conditions.

    Thanks in advance.

  6. I made some headway. After each array is created (Get…), I added a Select action specifying the three fields that will be used in a match. Then a Filter array action on the two outputs (contains or does not contain) gives me matching or not matching elements.

    Voila. Except I need all of the columns in each original array which disappear after Select, so I need to figure out how to reverse direction; go from the array from Filter array on the Select outputs back to the original array elements.

    One of the failings of Power Apps reaching its full potential to be codeless and for the average user is it’s byzantine reliance on JSON expressions and convoluted action definitions. While I don’t object, I have much less technical users who throw up their hands and roll their eyes. Worse is when I try and explain a level of complexity or difficult to a business owner.

    Thanks for your help

    1. I see the same problem with Power Automate. People are able to develop the sime stuff themselves. When it comes to real business solutions they often need help.

      This is where often consultancies can help to get past the hurdles.

      I have also tried with the many patterns on my site like try-catch, Pieter’s method and querying json to help.

      Maybe software development is just a speciality. There must be a reason why some people study for many years to become a software engineer.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.