How to check if an array contains value using Power Automate?

In this Power Automate tutorial, I will explain to you how to check if an array contains value using Power Automate. There are two ways we can check if an array contains a value in Power Automate.

  1. Using Contains Function
  2. Using Filter Array action

Scenario:
The flow uses manual triggers and initializes an array variable with an array value in it, and using the contains function in the compose data operation, it checks if an array contains the value or not using flow. If the value exists, it returns the output as true; else, it is false.

Follow the below examples to check if an array contains value using flow

Check if an array contains value using Power Automate

Let us see how to check if an array contains value using Power Automate or Microsoft Flow.

Example -1: (using contains function)

In this, we are going to use the contains function; the below code is a syntax for the contains function in Power Automate.

contains(collection: array|string, value: string)

Input parameters

  • collection is a mandatory field; pass the collection of array or string values.
  • value is a mandatory field; pass the value you want to check if it is contained in an array or string.

Output

Returns true if the values are contained in an array or string else false.

Follow the below steps to create a flow:

Step-1:

Create an instant cloud flow, enter the flow name, choose the trigger as a manual trigger, and click on the create option.

check if an array contains value using flow

Step-2:

See also  How to Set as Total in Power BI Waterfall Chart?

Select +New step and add an initialize variable action from the action triggers. Enter the variable name and choose the variable type as array. In the value section, pass the below code to create an array with the values.

createArray('Power Apps','Power Automate','Power BI','Power Virtual Agent','Power Pages')
How to check if an array contains value using Power Automate

Step-3:

Add a compose data operation and pass the below expression under the expression tab. I have passed the value Power BI to check whether it is presented in the PowerPlatforms array.

If it is contained, it returns a true value; else false.

contains(variables('PowerPlatforms'),'Power BI')
How to check if an array contains value using Power Automate flow

Step-4:

Save and Run the flow by selecting the run flow option. Once the flow runs successfully, it returns the true value in the compose data operation output section.

Power Automate check if an array contains value example

This is how to check if an array contains value using the contains function in Power Automate flow.

Example -2: (using Filter Array function)

Now, we will see how to use the Power Automate Filter Array function to check if the value exists in an array or not using Flow.

In this example, I will use the same array created for the Previous example called Power Platforms.

Follow ( Step -1 and Step -2) from the previous example to create an instant cloud flow and initialize the array variable with the values.

Step-3:

  • Select + New step and choose the Filter array action from the action triggers. In the From section, pass the dynamic content of the initialized variable.
  • And check the condition item() contains a value. Here, I have entered the value as Power, so it checks the array item that contains the value Power and returns it in the output section.
How to check if an array contains value using the Power Automate

Step-4:

See also  How to Change Trigger in Power Automate [3 Different ways]

Save and run the flow by clicking on the run flow option. Once the flow runs successfully, like below, it returns the values containing Power in an array.

Example to check if an array contains value using Power Automate flow

Similarly, when I change the value to Power Pages and run the flow.

Power Automate check if an array contains value

In the output field, we can see that it returns only the value passed contained in an array.

Example to check if an array contains value using Power Automate

This is how to use the Filter Array function to check if the value exists in an array or not using Flow.

Conclusion

Here, we learned how, by using the contains function or the filter array action, we can check whether a value exists in an array in Power Automate.

You may also like:

>