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.
- Using Contains Function
- Using Filter Array action
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)
- 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.
Returns true if the values are contained in an array or string else false.
Follow the below steps to create a flow:
Create an instant cloud flow, enter the flow name, choose the trigger as a manual trigger, and click on the create option.
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')
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.
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.
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.
- 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.
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.
Similarly, when I change the value to Power Pages and run the flow.
In the output field, we can see that it returns only the value passed contained in an array.
This is how to use the Filter Array function to check if the value exists in an array or not using Flow.
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:
- How to merge arrays in Power Automate?
- How to create an array from JSON objects using Power Automate?
- Create an Array from SharePoint list Items using Power Automate
- How to Get Unique Values from an Array in Power Automate?
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.