This Power Automate tutorial explains how to use the Power Automate contains() function. I will show you the contains() Power Automate string function with syntax and examples.
In addition, I will explain how to use this contains() function in a Power Automate flow based on a SharePoint list.
Power Automate Contains() Function
Microsoft provides many string functions in Power Automate to manipulate strings. One of the important functions is the contains() function in Power Automate. This function can be used with arrays or strings.
The Power Automate contains() function is used to check if the array or string contains a specific element or a substring value. If the string or array contains the value, then it will return the output as ‘True’ or return the output as ‘False’.
Note:The contains function only works if the value contains exact matches only.
Contains() Function Syntax
This syntax of the Power Automate contains() function is:
Syntax: contains(collection: array|string, value: string) (OR) contains([string],[value])
Example: contains([‘European countries – Germany, France, Austria],[‘France’]) => Return the output as ‘true’.
The output datatype returned will be in the form of boolean values ‘true or false’.
Power Automate Contains() Function Examples
To understand this function, let’s implement it in a Power Automate flow that will trigger manually.
Follow step-by-step instructions to create a Power Automate flow.
1. Open the Power Automate home page by typing make.powerautomate.com in the browser. Click on “+Create” -> Select “Instant cloud flow. ” Then, set the flow name, choose “Manually trigger a flow,” and click on Create.
2. In this step, add an “Initialize variable” and set the details below.
- Name: Set a name for an initialized variable
- Type: Select datatype as ‘String’
- Value: Here, I have given a text string value.
3. Finally, add a “Compose” data operation and set the Input value as placed in the code.
contains(variables('Power Platform'),'Power BI')
Where variables(‘Power Platform’) – String, and ‘Power BI’ – Value/element.
4. The flow is ready, and we can test it. Save the flow and Click on Test -> Manually to test flow.
5. The outputs of the compose action will display true like below if the string contains a specific value.
This is how to work with the Power Automate contains() function.
Now, let us discuss the second example of the Power Automate string contains() function, based on the SharePoint list.
Recently, I was working on a SharePoint list where the client is required to check whether a text column has specific values.
For that, I created a SharePoint list named “Course Enrollment Form” with datatypes as provided in the table below.
|Course to enroll||Single line of text -By default it is a Title column|
|Full Name||Single line of text|
|Date of Enrolling||Date and Time column|
Here, we wanted to verify whether the “Course to Enroll” column contains designated course values.
For this, build an “Automated cloud flow” in a Power Automate flow that will trigger automatically when an item is created or modified in a SharePoint list.
Follow the below step-wise process to implement it inside a flow.
1. In the Power Automate Home page, click on +Create and select “Automated cloud flow”. Then, set the flow name, choose the trigger “When an item is created or modified” and click on Create. Here are the details below:
- Site Address: Select a site name from the drop-down.
- List Name: Choose a list name from the drop-down.
2. Next, add an “Initialize variable” flow action that stores variable value and is used during the flow. Provide details below.
- Name: Give a name for the variable.
- Type: Select datatype from the drop-down.
- Value: Select value from the dynamic content.
3. Finally, add a “Compose” data operation and set the details below.
- Inputs: Take the below given code value in it.
4. The flow has been created. Now, it’s time to test. Click on Save and Test -> Test Manually.
5. Then, the outputs of the compose flow action will give the result as true or false if the text has that specific value.
This is how to use the contains() string function in a Power Automate flow.
I hope you got an idea of Power Automate contains() function. With two examples, I have explained how to use the contains() function in Power Automate. One is from a manual trigger flow that only shows the result of the contains string function. The other one is on automatically trigger flow using a SharePoint list.
You may like the following tutorials:
- Power Automate toLower() Function
- Power Automate IndexOf() Function
- Length Function in Power Automate
- Power Automate startswith Function
- Power Automate Chunk() Function
- Power Automate isFloat() Function
Preeti Sahu is an expert in Power Apps and has more than 6 years of experience working with SharePoint and the Power Platform. As a Power Platform expert for Power BI, Power Apps, Power Automate, Power Virtual Agents, and Power Pages, she is currently employed with TSinfo Technologies. She is the author of the book Microsoft Power Platform A Deep Dive. She also made a big technical contribution to SharePointDotNet.com in the form of articles on the Power Platform. She enjoys traveling and spending time with her family in her spare time.