简体   繁体   English

Tableau:我需要了解两个日期之间的天数差异。 Datediff提供的结果不正确,为什么?

[英]Tableau: I need to get the difference in days between two dates. Datediff is giving incorrect result, why?

I am using DATEDIFF as 我正在使用DATEDIFF作为

DATEDIFF('day', #2016-12-24#, #2016-12-22#)

I am getting the result as -1468. 我得到的结果是-1468。 If I interchange the dates, I am getting 1468 While the difference is just 2 days. 如果我互换日期,我会得到1468,而差额只有2天。

If I use DATEDIFF('day', #2016-12-24#, TODAY()) I am getting 8808. why? 如果我使用DATEDIFF('day', #2016-12-24#, TODAY())我会收到8808。为什么? Any help is greatly appreciated in getting the dates difference properly. 非常感谢您提供任何帮助,以正确获取日期差异。

Weird problem with Tableau. Tableau的奇怪问题。 Here is the solution. 这是解决方案。 https://community.tableau.com/thread/122324 https://community.tableau.com/thread/122324

Tableau automatically uses SUM() when we drag this field into rows/columns. 当我们将该字段拖到行/列中时,Tableau自动使用SUM()。 We need to use non-additive aggregation like MIN() MAX() AVG() or MEDIAN(). 我们需要使用诸如MIN()MAX()AVG()或MEDIAN()之类的非加法聚合。

Thanks Shawn, for your answer in the Tableau Community. 感谢Shawn,感谢您在Tableau社区中的回答。

DATEDIFF的格式功能:DATEDIFF(date_part,[开始时间],[结束时间]。由于首先使用结束时间,随后使用开始时间,所以显示-1468。请确保开始时间和结束时间为字符串格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM