July 21, 2024

In Power Automate, we need to parse a lot of strings and collections and, sometimes, it’s essential to understand if we have something that exists inside another collection. Power Automate has the “contains” function that helps with this.

For example, if you want to go through a list of people and get the unique names, you would need to:

  1. Define an array variable
  2. For each element
  3. If it exists in the collection, add it to the array.

It’s a simple example, but it would be a lot harder without the “contains” function.

Although the function is used a lot with variables, it can be used in any collection.

So let’s see how to use it.


It follows a simple pattern.

  1. Collection (either a string or an object)
  2. Value to search

Let’s start with a simple example:


will return 


It makes sense since two exist somewhere in the collection. But how about if we provide the number “two” instead of the string “two”?


will return 


The number will be converted to a string and then compared. Speaking of comparisons, let’s try with spaces and see what we get.

contains(variables('STRING_ARRAY'),' T ')

will return


The string needs to match the absolute value. So let’s try the opposite way.

createArray('Manuel',' T ', 'Gomes')

will return


Again, the string needs to match with the exact same characters.

Let’s try with boolean values:

contains(variables('BOOLEAN_ARRAY'), false)

will return


How about this?


will return


Why? The datatypes are different, so the comparison fails. Second, the behavior is a bit different from integer values like we’re seen above.

Finally, let’s test another collection.


will return


Although they have the same structure, Power Automate will consider the second parameter as a string and not an array. However, notice that we can use it safely on the right-hand parameter, considering it as an array.


will return


You can replace all notations of the createArray function with the string as above, and it will work the same way.


Depending on the size of your string, your expression may return an error, even if it’s correct. Please note that the expressions have a max size of 8,192 characters. If you have an expression that is even bigger than 1000, I would strongly advise breaking it into smaller, manageable formulas.

Also, you can’t compare arrays with this method, and you should be careful with the conversions, as we’ve seen above. But, again, this is because different types behave in another way.


Here are some things to keep in mind.

Use “debug” compose actions.

Since the comparison will return true or false, sometimes it’s tricky to understand how the calculation is done, depending on how complex the expression is. So I recommend using Compose actions to have the values that go “in” the function. This way, if the value doesn’t make sense, you can understand, based on the parameters, why it was calculated that way.

Don’t nest

There’s no real reason to do it. Furthermore, if you try to nest “contains” functions, you’ll receive an error since we don’t have a collection to compare. So be very careful to avoid breaking Flows.


Microsoft’s contains Function Reference

Back to the Power Automate Function Reference.

Photo by Michael Dziedzic on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

2 thoughts on “Power Automate: contains function

  1. Hi, can the contains function be used in the below scenario? I tried different various and all return false…

    1. Hi Liz,
      Searching in JSON arrays is hard with the “Compose” function, but you can use the Filter Array. I’ll write an article in the future, but you can use the Filter Array action with an equals like this:

      You’ll get the following:

      Can you please try and let me know if it works?

Leave a Reply to Manuel Gomes Cancel reply

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