Category / Section
How can I fix the 'CONTAINS' function not working in an IF statement?
Published:
This article will guide you to use ‘CONTAINS’ function in an IF statement.
Understanding the ‘CONTAINS’ Function and its usage in IF statement:
- The ‘CONTAINS’ function is used to check if a value is present in a string or a list of values.
- It returns a boolean value (true or false) based on whether the specified value is found or not.
- When using the ‘CONTAINS’ function in an IF statement, it is important to consider how the boolean value is evaluated.
Resolving issues with the ‘CONTAINS’ function in an IF statement:
Cause:
- The common mistake done for the ‘CONTAINS’ function in an IF statement was:
if(CONTAINS([sample],'Security'),1,0)
- Here, the ‘CONTAINS’ function was not checked in the IF statement, resulting in an error.
Solution:
- The correct syntax for using ‘CONTAINS’ in an IF statement should be:
If(CONTAINS([sample],'Security')='true',1,0)
- Here, the ‘CONTAINS’ function is used to check if the value ‘Security’ is present in the list ‘sample’, and then the Boolean value is compared to the string ‘true’ using the ‘=’ operator. If the Boolean value is true, then the expression evaluates to 1, otherwise, it evaluates to 0.