首页 > 解决方案 > 如何在 Tableau 中制作仪表板日期参数,默认为本月的第一天到现在?

问题描述

我正在尝试在我的 Tableau 仪表板上进行一个日期控件作为日常滑块,默认为从当前月份的第一天到现在。但它可以一直向后滑动到我参考字段的最早日期。

因此,当用户打开仪表板时,它最初看起来像:

[Or back to 2018-01-01] 05-01-2021<----------->05-30-2021 [Can be incremented down by day if the user wants]

我怎样才能做到这一点?举例来说,我想将其基于日期字段为 Inserted At 的 Users 表(其最小日期为 2018-01-01,最近的数据截至 05-30-2021)。

在 SQL 中,这看起来像:

DATETRUNC('month',NOW())<----->NOW()

在仪表板上,我希望将此作为参数,因为我想将其用作多个不同工作表上的过滤器,用于具有不同日期的表,我想对其进行过滤。

我试过了:

1) Going to my Users table in a worksheet
2) Creating a calculated field called "This Month Start" defined as DATETRUNC('month',NOW())
3) Right clicking on This Month Start and going to Create->Parameter
4) Setting "When This Workbook Opens" to Users."This Month Start" as "This Month Start Parameter"
5) Creating a calculated field from the Parameter "This Month Start Parameter" as [Users.Inserted At] >= [This Month Start Parameter] and using it as a Filter to select True values.

之后,我对如何将参数链接到仪表板感到困惑。例如,我可以将另一个只是 NOW() 的参数设置为“本月结束参数”作为我的结束范围,但我不知道如何将开始/结束用作用户可以调整的日历到/从在仪表板上。

我找到的最接近的解决方案是 Tableau 的本教程,但它并没有让我解决问题:

“如何在 Tableau 中创建默认为今天和日期参数的日期过滤器” https://www.youtube.com/watch?v=QAdeEKX3p0s

更新

到目前为止,一条路径似乎是:

1) Make 2 calculated fields with DATETRUNC('month',NOW()) as "This Month Start" and NOW() as "This Month End"
2) Make a Param "Start Date" with initial values when opening workbook as "This Month Start" and with a Range of values from Users.Inserted At
3) Make a Param "End Date" with initial values when opening workbook as "This Month End" and with a Range of values from Users.Inserted At
4) Make a calculated field called "Users Start Date" where [Inserted At] >= [Start Date] and add this as a filter to the workbook for True values.
5) Make a calculated field called "Users End Date" where [Inserted At] <= [End Date] and add this as a filter to the workbook for True values.
6) Right click the params "Start Date" and "End Date" and add them to the workbook via Show Parameter.

但是,我仍然无法让这两个控件成为单个 To/From 控件。

在此处输入图像描述

标签: sqltableau-api

解决方案


推荐阅读