← Al Davies, 250 High Street

How to check if text or a list contains a value in Power Automate

Use the contains() expression. For text, write contains('hello world', 'world'). It returns true or false, and the check is case-sensitive.

What does the contains() function do?

The contains() function checks whether a collection holds a specific item. Microsoft documents it as contains(collection, value). It returns true when the item is found and false when it is not.

It works on three types: a string to find a substring, an array to find a value, and a dictionary (an object) to find a key. Microsoft states that the function is case-sensitive.

How do you check if text contains a word?

  1. Add a Condition action, or a Compose action to test the result first.
  2. Select the left box and open the Expression tab.
  3. Type contains(triggerOutputs()?['body/Title'], 'urgent'), with your own column name in place of Title.
  4. Select Add, then set the Condition to is equal to true.
  5. Save and run the flow. Check the run history for true or false.

Why does contains() miss a word that is there?

The check is case-sensitive. The text 'Urgent' does not match 'urgent'. Microsoft documents this behavior.

To ignore case, change both sides to lower case with toLower(). For example, write contains(toLower(triggerOutputs()?['body/Title']), 'urgent').

How do you check if a list contains an item?

Pass the array as the first argument. For example, contains(variables('Approvers'), 'ana@contoso.com') returns true when that exact text is one of the items.

The match is exact for each item. A list that holds 'ana@contoso.com' does not match the partial text 'ana'. To search part of each item, loop over the list or filter it first.

How do you check if an object has a key?

Pass the object first and the key name second. For example, contains(body('Parse_JSON'), 'email') returns true when the object has a key named email.

Use this check before you read a key that may be missing. It stops a flow from failing on a missing field. The key test says nothing about whether the value is empty. For empty values, see how to test for an empty field.

Why does contains() fail on a SharePoint choice or person column?

A choice, person or lookup column returns an object, not plain text. Passing the whole object as the first argument checks object keys, not the text you see. Read the text value first, for example the Value property of a choice column.

If a condition on a choice column does not match, read choice column condition not matching. Test with your own data and check the exact output in run history.

What if the value is null?

A null value can break an expression with an invalid type error. Microsoft says that when conditions compare values, null becomes an empty string, but contains() itself expects text, an array or an object. Guard the input with coalesce(), for example contains(coalesce(triggerOutputs()?['body/Notes'], ''), 'refund').

See the invalid type error about null for more fixes. To split text into parts before you check it, use the split string guide.

FAQ

Is contains() case-sensitive in Power Automate?

Yes. Microsoft documents it as case-sensitive. Use toLower() on both sides to ignore case.

Can contains() check more than one word at once?

Not in one call. Join several checks with or(), such as or(contains(x, 'a'), contains(x, 'b')).

What does contains() return?

It returns a Boolean: true when the item is found, false when it is not.

Is there a contains operator in the Condition action?

Yes. The Condition action has a contains option in its operator list. It does the same job without an expression.

Sources