3 Ways to Check if an Array Contains a Specific Value in Power Automate

Do you need to check if a certain value exists in an array?

Arrays are used to store multiple items in a single variable. Arrays are often what is returned when connecting to external data sources in your flow.

A common task when handling arrays is to check if the array contains a specific value.

This article will explore a few methods on how to perform this check in Power Automate.

What is an Array?

An array is a data structure in Power Automate that stores multiple values in a single variable. For example, you might use an array to store names, email addresses, or ages.

["Mark", "Jennifer", "Steve"]

The above example shows an array of 3 names.

Check if Array Contains a Specific Value with the Contains Function

In Power Automate, you can use the contains function to check if an array contains a specific value.

The contains function has a simple syntax, ideal for implementing it in your workflow.

contains(<array>, <value>)
  • <array>: The array you want to search in.
  • <value>: The value you’re looking for within the array.
contains(outputs('Compose'),'Jennifer')

The above example of the contains function will check the array in the Compose action and see if it contains the name Jennifer.

It returns true if the item is found and false otherwise.

📝 Note: The contains function works with exact matches only. For example, searching for Jen will result in a false value from the contains function even though the array contains a Jennifer.

Check if Array Contains a Specific Value with the Filter Action

In Power Automate, you can use the Filter array action to check if an array contains a specific value.

  1. First, add a Filter array action in your flow.
  2. Provide the array you want to check in the From input fields.
  3. Add an item() expression in the Choose a value field on the left side of the condition. This allows the filter action to check each item in the array.
  4. Select the is equal to condition from the dropdown list.
  5. Add the item you want to search the array for in the Choose a value field on the right side of the condition. In this example, the Filter array action will return all the items in the array that equal the text Jennifer.

If the value exists in the array, the Filter array will return an array with at least one value. This might be sufficient, but if you need you can use another expression to test if the output contains an items.

not(equals(length(body('Filter_array')),0))

The above expression will return true if the item exists in the array and false otherwise.

The length function returns the number of items in the output array. If this is not equal to zero, then the specific item must exist in the original array.

Check if Array Contains a Partial Match Value with the Filter Action

The Filter array action can also be used to test for a partial match in your array with a slight modification.

Select the contains option for the condition and now the Filter array action will return any item in the array that contains the text you’re testing.

Check if Array Contains a Specific Value with the Condition Action

The Condition action has a similar condition interface as the Filter array action and will allow you to create a similar test for a specific value in an array.

Here is how to use the Condition action to check if an array contains a specific value.

  1. Add the Condition action to your flow.
  2. Add the array you want to test to the Choose a value field on the left.
  3. Select the contains option as the condition from the dropdown.
  4. Add the value you want to check to the Choose a value field on the right.

If the array contains the specific value, the condition will be evaluated as true, and the actions inside the Yes branch will execute. If the array does not contain the value, the actions inside the No branch will execute instead.

Conclusions

Checking if an array contains a specific value can be done in several ways.

Using the contains function, the Filter array action, or the Condition action are all potential solutions.

The Filter array action has the added benefit that it allows you to check for exact or partial matches within the array.

What is your preferred method for checking values in your arrays? Let me know in the comments.

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

0 Comments

Submit a Comment

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

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!