tableau中计算字段的多个if

发布于 2024-10-28 01:04:40 字数 286 浏览 2 评论 0原文

请原谅这个绝对新手的问题,但我对画面很陌生。 我想做的是根据哪些过滤器标志处于活动状态创建一条消息。所以,在伪代码中,我会做这样的事情:

message = ''
if filter1 == 1:
  message += 'filter 1 is active'
if filter2 == 1:
  message += ' filter 2 is active'
return message

问题是,我什至不确定如何执行多个 if 语句 - 我不断收到语法错误。任何帮助将不胜感激。

please pardon the absolutely newbie question but i'm very new to tableau.
what I'd like to do is create a message based on which filter flags are active. so, in psuedo code, i'd do something like this:

message = ''
if filter1 == 1:
  message += 'filter 1 is active'
if filter2 == 1:
  message += ' filter 2 is active'
return message

problem is, I'm not even sure how to do multiple if statements - i keep getting a syntax error. Any help will be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

下面是我如何完成类似任务的示例:

IF [ZAVUFA1_FED_COLL_CHOICE_1] = 'xxxxx' THEN 1
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_2] = 'xxxxx' THEN 2
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_3] = 'xxxxx' THEN 3
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_4] = 'xxxxx' THEN 4
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_5] = 'xxxxxx' THEN 5
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_6] = 'xxxxx' THEN 6
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_7] = 'xxxxxx' THEN 7
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_8] = 'xxxxxx' THEN 8
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_9] = 'xxxxx' THEN 9
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_10] = 'xxxxxx' THEN 10
ELSEIF ISNULL([ZAVUFA1_FED_COLL_CHOICE_1]) THEN 99
END

尽管我很喜欢 stackoverflow,但 Tableau 在其网站上也有一个很棒的用户论坛。

Here is an example of how I accomplished something similar:

IF [ZAVUFA1_FED_COLL_CHOICE_1] = 'xxxxx' THEN 1
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_2] = 'xxxxx' THEN 2
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_3] = 'xxxxx' THEN 3
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_4] = 'xxxxx' THEN 4
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_5] = 'xxxxxx' THEN 5
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_6] = 'xxxxx' THEN 6
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_7] = 'xxxxxx' THEN 7
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_8] = 'xxxxxx' THEN 8
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_9] = 'xxxxx' THEN 9
ELSEIF [ZAVUFA1_FED_COLL_CHOICE_10] = 'xxxxxx' THEN 10
ELSEIF ISNULL([ZAVUFA1_FED_COLL_CHOICE_1]) THEN 99
END

As much as I love stackoverflow, Tableau also has a great user forum on their site.

阳光的暖冬 2024-11-04 01:04:40

您可以使用以下代码创建一个名为 message 的计算字段:

IF filter1 = 1 THEN 'filter 1 is active' END
+ IF filter2 = 1 THEN ' filter 2 is active' END

You would create a calculated field called message with this code:

IF filter1 = 1 THEN 'filter 1 is active' END
+ IF filter2 = 1 THEN ' filter 2 is active' END
我的痛♀有谁懂 2024-11-04 01:04:40

我最终做的是为每个 if 语句创建一个计算字段。然后,我创建了另一个计算字段,该字段连接我创建的第一组计算字段中每个字段的所有输出。看起来有点像黑客,所以如果有人知道一种更优雅的方法来做到这一点(使一系列计算字段的计算字段看起来非常笨拙),我很高兴传递回答要点。

what I ended up doing is creating a calculated field for each if statement. I then created yet another calculated field that concatenates all of the output from each of the first set of calculated fields I created. Seems like a bit of a hack so If anyone knows of a more elegant way of doing this (making a calculated field of a series of calulated fields seems awfully kludgy) I'd be glad to pass on the points for answering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文