简体   繁体   English

从 Tableau 中的表中排除多个值

[英]Exclude multiple values from a table in Tableau

Tableau question画面问题

I am new to Tableau.我是 Tableau 的新手。 I have a field name [Fruit description] and I am trying to exclude a lot of values using key words.我有一个字段名称 [Fruit description],我正在尝试使用关键字排除很多值。 For example, I was to exclude all values that have the phrase [very red] or [juicy] etc.例如,我要排除所有包含 [very red] 或 [juicy] 等短语的值。

I have tried multiple syntaxes using the IF Contains([field], [substring])=true ... I am doing something very wrong..我已经使用 IF Contains([field], [substring])=true 尝试了多种语法......我做错了什么......

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.我也试过说 =true then 0 else 1 但这些都没有奏效。 I get syntax errors..我收到语法错误..

Any help?有什么帮助吗? :) Thanks :) 谢谢

You don't have to say "= true".您不必说“= 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然后你可以定义一个布尔值的计算字段,比如[Tasty?]作为

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.然后您可以在任何架子或计算字段上使用 [Tasty?],包括“过滤器”架子。 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.在布尔值字段名称的末尾,因为它使该字段的 True 或 False 的含义显而易见。 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?]您还可以为您的字段编辑别名,以便您显示的标签更加明显 - 例如使用别名 Tasty 和 Yucky 来代替字段 [Tasty?] 的 True 和 False 显示。

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.最后,如果您要对大数据进行大量这样的字符串比较,您可能需要寻找更有效的方法,例如使用正则表达式或预计算 - 使用 Tableau Prep Builder 或创建数据提取。

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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