Naga Vemprala
Naga Vemprala

Reputation: 728

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

I am using DATEDIFF as

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

I am getting the result as -1468. If I interchange the dates, I am getting 1468 While the difference is just 2 days.

If I use DATEDIFF('day', #2016-12-24#, TODAY()) I am getting 8808. why? Any help is greatly appreciated in getting the dates difference properly.

Upvotes: 1

Views: 6277

Answers (2)

Jashandeep Kaur
Jashandeep Kaur

Reputation: 1

Format for DATEDIFF Function: DATEDIFF(date_part, [Start Time], [End Time]. It is showing -1468 because you're using end time first and start time later. Make sure your start and end times are in string format.

Upvotes: 0

Naga Vemprala
Naga Vemprala

Reputation: 728

Weird problem with Tableau. Here is the solution. https://community.tableau.com/thread/122324

Tableau automatically uses SUM() when we drag this field into rows/columns. We need to use non-additive aggregation like MIN() MAX() AVG() or MEDIAN().

Thanks Shawn, for your answer in the Tableau Community.

Upvotes: 3

Related Questions