cube-js / cube-js/cube

Query specified timeDimension granularity offset?

Open
#10,042 2 comments 2 reactions 1 assignee Claimed by @igorlukanin View on GitHub
question
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Problem**

I'd like to be able to customize the 'offset' of timeDimension granularities at query time. For example, I want to support a client that maybe wants to group by a time dimension with daily granularity, but for that day to map to 2:30am -> 2:30am.

For example, if there's the following data with a created_at time at:

- 2025-01-01T00:00:00Z
- 2025-01-01T01:00:00Z
- 2025-01-01T02:00:00Z
- 2025-01-01T03:00:00Z

I want the ability to have the query timezone be UTC, group by created_at with granularity daily, but offset that granularity by -2.5 hours, with the expected result (date, count):

1. 2025-12-31, 3
2. 2025-01-01, 1

I can define [custom granularities ](https://cube.dev/docs/product/data-modeling/recipes/custom-granularity) for pre-defined offsets, but I want this to be able to be supplied by clients at query time. This is a viable but non-ideal workaround for supporting hour shifts, but moving to supporting minute shifts causes a significant number of custom granularities and bloats the data model.

This would also be an alternative to supporting weekly aggregations on different starting days of week, without adding 7 custom granularities to every time dimension.

I could pass in a timezone that maps to the required shift - but this is extremely unintuitive to ask a client to do, and doesn't fully solve the problem (for example, I'd still want to respect DST change in the client's actual timezone).

Is there a way to do this with cube today?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.