Bonnard Docs

Time

Enable time-based analysis with time dimensions.

Overview

Time dimensions (type: time) enable powerful time-based analysis including granularity selection, date ranges, and rolling windows. They're essential for any time-series analytics.

Example

dimensions:
  - name: created_at
    type: time
    sql: created_at

  - name: order_date
    type: time
    sql: DATE(ordered_at)

Time Granularities

When querying a time dimension, you can specify granularity:

GranularityDescription
secondGroup by second
minuteGroup by minute
hourGroup by hour
dayGroup by day
weekGroup by week (Monday start)
monthGroup by month
quarterGroup by quarter
yearGroup by year

Query Usage

Time dimensions can be used in timeDimensions for special handling:

\{
  "measures": ["orders.count"],
  "timeDimensions": [\{
    "dimension": "orders.created_at",
    "granularity": "month",
    "dateRange": ["2024-01-01", "2024-12-31"]
  \}]
\}

Date Ranges

Common date range options:

  • "today", "yesterday"
  • "this week", "last week"
  • "this month", "last month"
  • "this year", "last year"
  • "last 7 days", "last 30 days"
  • ["2024-01-01", "2024-12-31"] (custom range)

Best Practices

Use Native Timestamps

# Good - preserves precision
- name: created_at
  type: time
  sql: created_at

# Avoid - loses time component
- name: created_at
  type: time
  sql: DATE(created_at)

Multiple Time Dimensions

A cube can have multiple time dimensions for different purposes:

- name: created_at
  type: time
  sql: created_at

- name: shipped_at
  type: time
  sql: shipped_at

- name: delivered_at
  type: time
  sql: delivered_at

Timezone Handling

For consistent timezone handling, convert in SQL:

- name: created_at
  type: time
  sql: "CONVERT_TIMEZONE('UTC', 'America/New_York', created_at)"

See Also

  • cubes.dimensions
  • cubes.dimensions.types
  • cubes.measures.rolling