How to Check If an array Contains a Value using Power Automate?

When working with Power Automate, there will be situations where we need to check if an array contains a specific value or a partial text.

For this, Power Automate has a function named contains() function to check whether an array or a string contains a specific value.

In this tutorial, I will explain how to check if an array contains a specific value using the Power Automate contains() function and show how to check if an array contains a certain string with the filter array action in Power Automate.

Power Automate Array Contains() Function

Power Automate contains() function will check if an array or string contains a partial text or a specific element.

The output returned will be ‘true‘ if the array or string contains a specific element; else, it will return as ‘false.’

Power Automate contains() function is case-sensitive; it only checks for the exact match of an element.

InputFunctionOutput
‘Lidia’, ‘Henrietta’contains(“Lidia”,”Henrietta”),’Lidia’true
‘Lidia’, ‘Henrietta’contains(“Lidia”,”Henrietta”),’Lidia Holloway’false

Power Automate Check if an Array Contains a Value using contains() function

Here, I will discuss how to check whether an array contains a specific element by using the Power Automate contains() function.

I have explained the Power Automate contains() function in the above section.

Example:

InputExpressionoutput
[“California”,”Florida”,”Texas”]contains([“California”,”Floria”,”Texas”],’Florida’)true

Check the below-mentioned steps:

1. Navigate to the Power Automate home page and click “+Create” -> Select “Instant cloud flow. ” Then, set the flow name, choose “Manually trigger a flow,” and click on the Create button.

2. Take a new step as the Initialize variable flow action to initialize the values of an array.

Configure the below parameters:

  • Name: Set a name for an initialized variable.
  • Type: Select datatype as ‘Array’.
  • Value: Here, I have taken the below-shown values.
power automate check if array contains value

3. Add a Compose flow action to include the contains() expression to check whether the array has a specific element or not.

Inputs: Provide the below-given expression in it.

contains(variables('United States'),'Florida')
power automate check if value exists in array

4. Once the flow is ready. Save it and Test it Manually. Click on Runflow.

5. If the array contains a given element, the output will be returned as ‘true‘ as shown below:

power automate check if value is in array

This is how to use the Power Automate contains() function to check whether the array contains a specific value.

Check if an array contains a specific value in Power Automate using Filter Array

Let’s see how to check if the array contains a specific value from the Power Automate filter array action.

Scenario:

The image below shows a SharePoint list with a Country column [Single line of text].

I wanted to check whether the Country column contains a specific country [Egypt] or not.

power automate array contains string

Go through the below steps:

  1. Take Manually trigger a flow trigger.
  2. Next, add the ‘Get items‘ flow action to retrieve all the items from a SharePoint list. Select the Site Address and List Name.
power automate check if value in array

3. Take an ‘Initialize Variable‘ flow action. Set a Name for a variable and datatype as ‘Array.’

power automate filter array contains

4. After that, add Append to array variable flow action. Set the below details:

  • Name: Choose a name from the drop-down.
  • Value: Select the ‘Country‘ column from dynamic content.

Then, For each loop will be added automatically.

power automate find value in array

5. Take a ‘Filter array‘ flow action. Provide the below details:

  • From: Take the value of a variable[Countries]
  • Filter query: Give the below expression
 @contains(@{item()},'Egypt')                             
power automate filter array contains string

6. Now save and test the flow. Test it manually.

7. When the flow runs successfully, open the filter array and check whether the array contains a specific element or not.

Refer to the image below:

power automate array contains

This is how to check if an array contains a specific value in the Power Automate filter array action.

Conclusion

I hope this tutorial helped you to check if an array contains a specific value or not using Power Automate.

Here, I have described two methods to check if the array contains a value in Power Automate.

  • By using Power Automate contains() function
  • Through Power Automate Filter array action

You may also like the following tutorials: