Tableau - 如何计算 date/time 差异并得到完整的 date/time?
Tableau - How to calculate date/time difference and result in full date/time?
我正在尝试计算连接时间和断开连接时间之间的差异。见下图。但是我使用的 DATEPART 公式只允许我使用一个参数(小时、分钟、秒...)
但是,如图所示,我有一个 ID,其中 2017 年 3 月 1 日断开连接 2:35:22PM 并在 2017 年 3 月 2 日 1:59:38 下午恢复连接
理想反应:23小时24分16秒
但使用公式:
ZN(LOOKUP(ATTR(DATEPART('minute', [Disconnected At])),-1)-(ATTR(DATEPART('minute', [Connected At]))))
它没用。
有人可以帮助我实现理想的响应吗?或者类似的结果可以给我完整的日期和时间?
谢谢
Tableau ScreenShot
在两个日期之间以秒为单位使用 DATEDIFF。然后创建一个计算字段如下:
//replace [Seconds] with whatever field has the number of seconds in it
//and use a custom number format of 00:00:00:00 (drop the first 0 to get rid of leading 0's for days)
IIF([Seconds] % 60 == 60,0,[Seconds] % 60)// seconds
+ IIF(INT([Seconds]/60) %60 == 60, 0, INT([Seconds]/60) %60) * 100 //minutes
+ IIF(INT([Seconds]/3600) % 24 == 0, 0, INT([Seconds]/3600) % 24) * 10000 //hours
+ INT([Seconds]/86400) * 1000000 // days
有关详细信息,请查看此博客 post 我从中获得此信息。 http://drawingwithnumbers.artisart.org/formatting-time-durations/
我正在尝试计算连接时间和断开连接时间之间的差异。见下图。但是我使用的 DATEPART 公式只允许我使用一个参数(小时、分钟、秒...)
但是,如图所示,我有一个 ID,其中 2017 年 3 月 1 日断开连接 2:35:22PM 并在 2017 年 3 月 2 日 1:59:38 下午恢复连接
理想反应:23小时24分16秒
但使用公式:
ZN(LOOKUP(ATTR(DATEPART('minute', [Disconnected At])),-1)-(ATTR(DATEPART('minute', [Connected At]))))
它没用。
有人可以帮助我实现理想的响应吗?或者类似的结果可以给我完整的日期和时间?
谢谢
Tableau ScreenShot
在两个日期之间以秒为单位使用 DATEDIFF。然后创建一个计算字段如下:
//replace [Seconds] with whatever field has the number of seconds in it
//and use a custom number format of 00:00:00:00 (drop the first 0 to get rid of leading 0's for days)
IIF([Seconds] % 60 == 60,0,[Seconds] % 60)// seconds
+ IIF(INT([Seconds]/60) %60 == 60, 0, INT([Seconds]/60) %60) * 100 //minutes
+ IIF(INT([Seconds]/3600) % 24 == 0, 0, INT([Seconds]/3600) % 24) * 10000 //hours
+ INT([Seconds]/86400) * 1000000 // days
有关详细信息,请查看此博客 post 我从中获得此信息。 http://drawingwithnumbers.artisart.org/formatting-time-durations/