Tableau question
I am new to Tableau. I have a field name [Fruit description] and I am trying to exclude a lot of values using key words. For example, I was to exclude all values that have the phrase [very red] or [juicy] etc.
I have tried multiple syntaxes using the IF Contains([field], [substring])=true ... I am doing something very wrong..
Here is what I have done:
If CONTAINS([fruit_description],"Very red")=true then "exclude"
ELSEIF [fruit_description], "juicy") =true then "exclude"
ELSEIF CONTAINS([fruit_description],"yummy")=true then "exclude"
ELSEIF CONTAINS([fruit_description],"very tasteful")=true then "exclude"
else "keep"
END
I also tried saying =true then 0 else 1 But none of these work out. I get syntax errors..
Any help? :) Thanks
You don't have to say "= true". That's redundant.
Its simpler and more readable to treat boolean expressions as first-class datatypes, just as you would treat integers or strings. You can then just define a boolean valued calculated field named, say [Tasty?] as
CONTAINS([fruit_description],"Very red") OR
CONTAINS([fruit_description], "juicy") OR
CONTAINS([fruit_description],"yummy") OR
CONTAINS([fruit_description],"very tasteful")
and then you can use [Tasty?] on any shelf or calculated field, including the Filter shelf. My personal convention is to put a ? at the end of the names of boolean valued fields, as it makes the meaning of True or False obvious for that field. You can also edit the aliases for you field so that the label you display is even more self apparent - such as using the aliases Tasty and Yucky to display in place of True and False for the field [Tasty?]
Finally, if you are doing a lot of string comparisons like this on large data, you might want to look for more efficient approaches, such as using regular expressions or precomputing the calculation - either with Tableau Prep Builder or by creating an extract.