From dd6810d5eb72e88c70a06ce55d27fbc620835f16 Mon Sep 17 00:00:00 2001 From: AvilaJulio Date: Tue, 30 Sep 2025 08:58:53 -0600 Subject: [PATCH] docs: Add time_dimensions parameter to pre-aggregations reference Added documentation for the time_dimensions parameter which allows defining multiple time dimensions with individual granularities for a single pre-aggregation. Changes: - Added new time_dimensions section after granularity section - Included code examples in both JavaScript and YAML - Added note in time_dimension section linking to time_dimensions - Added reference link for internal navigation --- .../reference/pre-aggregations.mdx | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/docs/pages/product/data-modeling/reference/pre-aggregations.mdx b/docs/pages/product/data-modeling/reference/pre-aggregations.mdx index fc73501d00215..549db7c010e94 100644 --- a/docs/pages/product/data-modeling/reference/pre-aggregations.mdx +++ b/docs/pages/product/data-modeling/reference/pre-aggregations.mdx @@ -647,6 +647,13 @@ cubes: A [`granularity`][self-granularity] **must** also be included in the pre-aggregation definition. + + +To define multiple time dimensions for a single pre-aggregation, use the +[`time_dimensions`][self-timedimensions] property instead. + + + ### `granularity` The `granularity` property defines the time dimension granularity of data @@ -694,6 +701,92 @@ The value can be either a default granularity (i.e., `second`, `minute`, `hour`, granularity][ref-custom-granularity]. This property is required when using [`time_dimension`][self-timedimension]. +### `time_dimensions` + +The `time_dimensions` property allows you to define multiple time dimensions for +a single pre-aggregation. Each time dimension is specified with its own +granularity. This is useful when you need to pre-aggregate data based on +multiple time columns. + + + +```javascript +cube(`orders`, { + sql_table: `orders`, + + pre_aggregations: { + multiple_time_dimensions: { + measures: [CUBE.count], + time_dimensions: [ + { + dimension: CUBE.created_at, + granularity: `day` + }, + { + dimension: CUBE.completed_at, + granularity: `day` + } + ], + partition_granularity: `month` + } + }, + + measures: { + count: { + type: `count` + } + }, + + dimensions: { + created_at: { + type: `time`, + sql: `created_at` + }, + + completed_at: { + type: `time`, + sql: `completed_at` + } + } +}) +``` + +```yaml +cubes: + - name: orders + sql_table: orders + + pre_aggregations: + - name: multiple_time_dimensions + measures: + - count + time_dimensions: + - dimension: created_at + granularity: day + - dimension: completed_at + granularity: day + partition_granularity: month + + measures: + - name: count + type: count + + dimensions: + - name: created_at + type: time + sql: created_at + + - name: completed_at + type: time + sql: completed_at +``` + + + +When using `time_dimensions`, you cannot use the [`time_dimension`][self-timedimension] +or [`granularity`][self-granularity] properties, as each time dimension defines +its own granularity. + ### `segments` The `segments` property is an array of [segments from the @@ -1755,6 +1848,7 @@ cubes: [self-rollupjoin]: #rollup_join [self-rolluplambda]: #rollup_lambda [self-timedimension]: #time_dimension +[self-timedimensions]: #time_dimensions [self-buildrange]: #build_range_start-and-build_range_end [wiki-olap-ops]: https://en.wikipedia.org/wiki/OLAP_cube#Operations [wiki-composable-agg-fn]: