status, city,
product_name, or created_at. Each dimension maps to a column or SQL
expression in your data source.
See the dimensions reference for the full list of
parameters and configuration options.
Defining dimensions
A dimension specifies the SQL expression and its type:Dimension types
Primary keys
Every cube that participates in joins should define aprimary_key dimension. Cube uses primary keys to avoid
fanouts — when rows get duplicated during joins and aggregates are
over-counted. Composite primary keys can be created by concatenating columns:
Time dimensions
Time dimensions are dimensions of thetime type. They enable
grouping by time granularity (year, quarter, month, week, day, hour, minute,
second) and are essential for time-series analysis.
Custom granularities
You can define custom granularities for time dimensions when the built-in ones don’t fit — for example, weeks starting on Sunday or fiscal years:See the following recipes:
- For a custom granularity example.
- For a custom calendar example.
Proxy dimensions
Proxy dimensions reference dimensions from the same cube or other cubes, providing a way to reuse existing definitions and reduce code duplication.Within the same cube
Reference existing dimensions to build derived ones without duplicating SQL:From other cubes
If cubes are joined, you can bring a dimension from one cube into another. Cube generates the necessary joins automatically:Time dimension granularity references
When referencing a time dimension, you can specify a granularity to create a proxy dimension at that specific granularity — including custom granularities:Subquery dimensions
Subquery dimensions reference measures from other cubes, effectively turning an aggregate into a per-row value. This enables nested aggregations — for example, calculating the average of per-customer order counts.order_count subquery dimension computes the order count per user.
The avg_order_count measure then averages those per-user values. Cube
implements this as a correlated subquery via joins for optimal performance.
See the following recipes:
- How to calculate nested aggregates.
- How to calculate filtered aggregates.
Hierarchies
Dimensions can be organized into hierarchies to define drill-down paths (e.g., Country → State → City):Next steps
- See the dimensions reference for all parameters
- Learn about measures for aggregated calculations
- Explore custom granularities for fiscal calendars and non-standard time periods