Return values where each statement is true Tableau

最后都变了- 提交于 2019-12-12 04:19:20

问题


I am attempting to return records where multiple fields may be missing values. I have the following statement:

IF ISNULL([Sales Team]) THEN 'Sales Team'
   ELSEIF ISNULL([Portfolio]) THEN 'Portfolio'
   ELSEIF ISNULL([Category Type]) THEN 'Category Type'
   ELSEIF [Datasource] = 'DS1' AND ISNULL([Item Class Dtl]) THEN 'Item Class Dtl'
   ELSEIF ISNULL([Market]) THEN 'Market'
END

If Sales Team and Portfolio are NULL in a single record I want to return Sales Team and Portfolio amounts under their respective rows. Due to the nature of the ELSEIF, Portfolio amounts are excluded when Sales Team is NULL.

My end goal is to take this from 10 workbooks in a dashboard down to two. I am currently making the check for NULLS on a singular basis and combining the results in a dashboard.

From this:

To this:

Is there another Tableau function I can use to achieve this or another way to rewrite this? Thanks!


回答1:


You need to break this out into separate calculated fields. So, for example, the Sales Team calc would look like:

IF ISNULL([Sales Team]) THEN 'Sales Team' END

Create one calculated field for each condition. You can then get multiple "true" results from a single record.


In response to the updated question:

If Sales Team and Portfolio are NULL in a single record I want to return Sales Team and Portfolio amounts

So, the consolidation of the multiple calculated formulas would happen in the formula that calculates the amount. I don't currently know what that amount formula looks like, so I will give a general example.

Formula that tests for NULL (Let's call this Sales Team Check) would look like:

IF ISNULL([Sales Team]) THEN [Sales Team Amount] ELSE 0 END

You would have a formula for each condition. Then, the consolidating formula would look like:

[Sales Team Check] + [Portfolio Check] + [Category Type Check] + [Datasource Check] + [Market Check]

The idea here is that instead of returning Text when you check the record for a NULL field, you return the amount, otherwise return zero. Then add up the result of those checks.



来源:https://stackoverflow.com/questions/44184589/return-values-where-each-statement-is-true-tableau

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!