I've posted some time ago about "rounding" timestamps and datetime values, but in the past few months BigQuery has added Time Series functions (in preview for now), making for a cleaner and simpler approach of this problem.
We now have DATE_BUCKET
, DATETIME_BUCKET
and TIMESTAMP_BUCKET
which will help us bucket dates, datetimes and timestamps, respectively.
In the example below, we're specifying the bucket size to be 15 minutes and the function groups each of our event_timestamps into their respective bucket.
Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.