Dimensions and measures

Define the attributes you group and filter by, and the aggregations you measure, in dbt-compatible YAML

Dimensions and measures are the queryable fields of a model. This page shows how to define them, with examples grounded in the Flax spec. They live under the flax: key of a dbt model, so the file stays a valid dbt schema file.

#Dimensions

A dimension is an attribute you group or filter by — an order's status, a customer's country, or the date an order was placed. Each dimension needs a name, a type, and a sql expression. In sql, ${column} refers to a column on this model.

flax:
  dimensions:
    - name: status
      type: string
      sql: ${status}
    - name: order_date
      type: time
      time_grains: [day, week, month, quarter, year]
      sql: ${created_at}

Dimension types are string, number, boolean, and time. A time dimension may declare time_grains — the buckets (day, week, month, quarter, year) a viewer can roll up to. Add a human-friendly label, a description, and set hidden: true to keep a field out of the explore picker while still using it in expressions.

#Measures

A measure is an aggregation over rows. Each needs a name and a type; most types also take a sql expression naming the column to aggregate.

flax:
  measures:
    - name: order_count
      label: Number of orders
      type: count
      sql: "*"
    - name: total_revenue
      label: Total revenue
      type: sum
      sql: ${amount}
    - name: completed_revenue
      label: Completed revenue
      type: sum
      sql: ${amount}
      filters:
        - ${status} = 'complete'

Supported measure types: count, count_distinct, sum, average, min, max, median, percentile, and number (a raw expression, not aggregated). A percentile measure takes a percentile: value between 0 and 1 (e.g. 0.25 for Q1).

#Filtered measures

The optional filters list holds SQL boolean expressions that are AND-ed into the aggregation. completed_revenue above sums amount only for rows where status = 'complete', so you can define revenue variants without new columns.

#Formats and labels

Use label to control how a field appears in the UI, and description to document intent — both surface in the explore experience and the AI assistant's context. Display formatting (currency, decimals, percentages) is applied at visualization time; see Formatting and theming.

Tip

Prefer defining a filtered measure over asking every analyst to add the same WHERE clause. Define once, reuse everywhere.

#Next steps