Forum Discussion

tstraker's avatar
tstraker
Frequent Visitor
6 years ago
Solved

Text.Contains Error "cannot convert the value [string] to type logic"

Hi,

 

I'm trying to createa  calculated column that will search [application names] and tag those can contain certain text.

 

My attempt is below:

operations tag = if(Text.Contains([Application Name], "CIP1" or "ETL" or "OPS", 1) > 0) 
then "Operations Component"
else ""

The error I recieve is as follows:

 

Expression.Error: We cannot convert the value "CIP1" to type Logical.
Details:
    Value=CIP1
    Type=Type

 

I understand the issue here is that I'm mixing boolean logic with a string but whats the best way to go about it?

 

I realise I could probably use a conditional column instead but I may have ALOT of values to search the database for so it makes sense for me to have it in a function as opposed to a "click click click click" process.


Should I be using another method or have I written the Text.Contains incorrectly?

  • Hi,

    Does this M language formula do the job?

    =if Text.Contains([Application Name], "CIP1")=TRUE or Text.Contains([Application Name], "ETL")=TRUE or Text.Contains([Application Name], "OPS")=TRUE then "Operations Component" else null

2 Replies

  • Hi,

    Does this M language formula do the job?

    =if Text.Contains([Application Name], "CIP1")=TRUE or Text.Contains([Application Name], "ETL")=TRUE or Text.Contains([Application Name], "OPS")=TRUE then "Operations Component" else null

  • kentyler's avatar
    kentyler
    Solution Sage

    This is from the example for text.contains

    EVALUATE
    	ROW(
    		"Case 1", CONTAINSSTRING("abcd", "bc"), 
    		"Case 2", CONTAINSSTRING("abcd", "BC"),
    		"Case 3", CONTAINSSTRING("abcd", "a*d"),
    		"Case 4", CONTAINSSTRING("abcd", "ef")
    	)
    You might use something like
     if(
    OR(
    OR(CONTAINSSTRING([Application Name], "CIP1"),CONTAINSSTRING([Application Name],"ETL"),
    CONTAINSSTRING([Application Name], "OPS"),
    "Operations Component,
    "")