【问题标题】:Calculated field not working as expected计算字段未按预期工作
【发布时间】:2016-05-26 23:58:25
【问题描述】:

下面提到的是获取前几个月的计算字段。

CASE [TimeFrame]
when 'DateMonth' then if [Months between today and Date]=0 then 'show' end
when 'Last2Months' then if [Months between today and Date]>=0 and [Months between today and Date]<=1 then 'show' end
when 'Last3Months' then if [Months between today and Date]>=0 and [Months between today and Date]<=2 then 'show' end
else 'hide'
end

上述计算在 Last2Months 和 Last3Months 上按预期工作,但未显示当月的任何结果。

例如,如果用户选择 11/1/2015 那么,

  • DateMonth 应该是 11 月 -- 目前没有显示任何数据...
  • Last2Months 应该是 11 月和 10 月——按预期工作
  • Last3Months 应该是 11 月、10 月和 9 月——按预期工作。

我还需要将月份添加为滚动总和并自动显示,而不是选择下拉菜单。

请找到所附的twbx。

任何意见将不胜感激。

【问题讨论】:

  • 似乎没有附加任何东西。

标签: tableau-api


【解决方案1】:

您的CASE 语句中有IF 语句,但没有ELSE,这意味着在某些情况下您会得到一些NULL(它们不会被CASE 中的ELSE 捕获) .

我会这样重写。看看这是否能让你得到结果:

IF [TimeFrame] = 'DateMonth' AND [Months between today and Date] = 0 THEN 'show'
ELSEIF [TimeFrame] = 'Last2Months' AND [Months between today and Date] >= 0 AND [Months between today and Date] <= 1 THEN 'show'
ELSEIF [TimeFrame] = 'Last3Months' AND [Months between today and Date] >= 0 AND [Months between today and Date] <= 2 THEN 'show'
ELSE 'Hide'
END

【讨论】:

  • IF [今天和日期之间的月份]=0 then '30Days' ELSEIF [今天和日期之间的月份]>=0 和 [今天和日期之间的月份]=0 和 [今天和日期之间的月份]
猜你喜欢
  • 2023-03-20
  • 2015-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-25
  • 2019-06-20
  • 2016-08-13
  • 1970-01-01
相关资源
最近更新 更多