简体   繁体   中英

Exclude multiple values from a table in Tableau

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.

If this is a direct copy of your calculated field though, you are missing a piece on you second row:

ELSEIF [fruit_description], "juicy") =true then "exclude"

should be

ELSEIF CONTAINS([fruit_description], "juicy") =true then "exclude"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM