Defining Metrics
Fact Tables and Metrics
Section titled “Fact Tables and Metrics”GrowthBook uses a two-layer model:
- Fact Table — a thin wrapper around a raw event table in your warehouse. It defines which SQL query surfaces the raw events and which columns represent the user ID, timestamp, and numeric value.
- Metric — a statistical definition built on top of a Fact Table. It says how to aggregate the raw events into a number per user per experiment.
This separation means you define your data shape once (Fact Table) and can compose many different metrics from it without duplicating SQL.
Metric types
Section titled “Metric types”| Type | Definition | Example |
|---|---|---|
| Proportion | Percentage of users who did the event at least once | Conversion rate, click-through rate |
| Mean | Average numeric value per user | Average order value, average session duration |
| Ratio | Numerator metric divided by denominator metric | Revenue per session, pages per visit |
Step 1 — Create a Fact Table
Section titled “Step 1 — Create a Fact Table”- In the left sidebar, go to Analysis then Fact Tables.
- Click Add Fact Table.
- Give it a name (e.g.
Orders). - Select your Data Source.
- Write the SQL query that surfaces the raw events. The query must return at minimum:
- A user identifier column
- A timestamp column
- (For mean/ratio metrics) a numeric value column
Example Fact Table SQL for an orders table:
SELECT user_id, timestamp, revenue_usdFROM `myproject.analytics.orders`WHERE timestamp >= '{{ startDate }}' AND timestamp <= '{{ endDate }}'- Map the User ID column and Timestamp column in the Fact Table settings.
- Click Save.
Step 2 — Define a Metric
Section titled “Step 2 — Define a Metric”- In the left sidebar, go to Analysis then Metrics.
- Click Add Metric.
- Choose the metric type: Proportion, Mean, or Ratio.
- Select the Fact Table you just created.
- For a Mean metric, choose the numeric value column (e.g.
revenue_usd). - Set the Metric Window — the time window after assignment in which to count events (e.g. 14 days). This prevents long-tail events from polluting the analysis.
- Optionally set:
- Minimum sample size — GrowthBook will not show results until this threshold is reached.
- Maximum percentage change — alerts you if uplift looks suspiciously large.
- Click Save Metric.
Sample metric SQL (direct SQL metric)
Section titled “Sample metric SQL (direct SQL metric)”For cases where a Fact Table is not the right abstraction, GrowthBook also supports defining a metric with raw SQL directly. Here is a proportion metric that counts users who placed at least one order:
-- Proportion metric: "Purchased"
-- Returns one row per user who placed an order.
-- GrowthBook computes the conversion rate: ordered_users / assigned_users.
SELECT
user_id,
timestamp
FROM
`myproject.analytics.orders`
WHERE
timestamp >= '{{ startDate }}'
AND timestamp <= '{{ endDate }}'