tableau中计算字段的多个if
请原谅这个绝对新手的问题,但我对画面很陌生。 我想做的是根据哪些过滤器标志处于活动状态创建一条消息。所以,在伪代码中,我会做这样的事情:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面是我如何完成类似任务的示例:
尽管我很喜欢 stackoverflow,但 Tableau 在其网站上也有一个很棒的用户论坛。
Here is an example of how I accomplished something similar:
As much as I love stackoverflow, Tableau also has a great user forum on their site.
您可以使用以下代码创建一个名为 message 的计算字段:
You would create a calculated field called message with this code:
我最终做的是为每个 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.