Duration dimension_group - Unexpected Results

PaulM1
New Member

Is there a way to force the grain when using Duration?

When using only a Duration of Days, Looker still DATEDIFFs by the time. I think generally, when people are expecting the lowest grain to be the date, they would expect this:

SELECT TIMESTAMPDIFF(DAY, CAST('2017-10-18 19:43:29' AS TIMESTAMP_NTZ) , CAST('2017-10-19 14:08:35' AS TIMESTAMP_NTZ) )
= 1

Not this (which is what Looker does):

SELECT (TIMESTAMPDIFF(DAY, CAST('2017-10-18 19:43:29' AS TIMESTAMP_NTZ) , CAST('2017-10-19 14:08:35' AS TIMESTAMP_NTZ) ) + CASE WHEN TIMESTAMPDIFF(SECOND, TO_DATE(CAST('2017-10-19 14:08:35' AS TIMESTAMP_NTZ) ), CAST('2017-10-19 14:08:35' AS TIMESTAMP_NTZ) ) = TIMESTAMPDIFF(SECOND, TO_DATE(CAST('2017-10-18 19:43:29' AS TIMESTAMP_NTZ) ), CAST('2017-10-18 19:43:29' AS TIMESTAMP_NTZ) ) THEN 0 WHEN TIMESTAMPDIFF(SECOND, TO_DATE(CAST('2017-10-19 14:08:35' AS TIMESTAMP_NTZ) ), CAST('2017-10-19 14:08:35' AS TIMESTAMP_NTZ) ) < TIMESTAMPDIFF(SECOND, TO_DATE(CAST('2017-10-18 19:43:29' AS TIMESTAMP_NTZ) ), CAST('2017-10-18 19:43:29' AS TIMESTAMP_NTZ) ) THEN CASE WHEN CAST('2017-10-18 19:43:29' AS TIMESTAMP_NTZ)  < CAST('2017-10-19 14:08:35' AS TIMESTAMP_NTZ)  THEN -1 ELSE 0 END ELSE CASE WHEN CAST('2017-10-18 19:43:29' AS TIMESTAMP_NTZ)  > CAST('2017-10-19 14:08:35' AS TIMESTAMP_NTZ)  THEN 1 ELSE 0 END END)
= 0

Is there a way around this?

I understand the math, and why the answer is resulting in zero. I just don’t understand why, when the only Duration I have selected is Days, Looker still diffs down to hours/minutes/seconds. Aside from expecting a different result based on days being the lowest grain, it also seems quite inefficient to run all those diff functions when the selected Dimensions are not even asking for it.

0 0 48
0 REPLIES 0
Top Labels in this Space
Top Solution Authors