From c44e9a1f7265be93cf3dac846801598dfc6df0c6 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:07:57 +0000 Subject: [PATCH 1/8] Update references/dimensions.mdx --- references/dimensions.mdx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/references/dimensions.mdx b/references/dimensions.mdx index 01d244db..391ffd71 100644 --- a/references/dimensions.mdx +++ b/references/dimensions.mdx @@ -414,6 +414,42 @@ You can set custom versions of time intervals by using additional dimensions and groups: ["Delivery Date"] ``` +### Reference time intervals in other dimensions + +You can reference specific time intervals of a dimension in other dimensions. When you define time intervals for a dimension (like `session_start`), Lightdash creates separate dimensions for each interval (e.g., `session_start_day`, `session_start_month`). You can reference these in custom SQL for other dimensions. + +For example, if you have a `session_start` dimension with time intervals defined, you can calculate the duration between two dates using the `DAY` interval: + +```yaml + - name: session_start + meta: + dimension: + type: timestamp + time_intervals: + - DAY_OF_WEEK_NAME + - WEEK + - MONTH + - RAW + - DAY + - HOUR_OF_DAY_NUM + - QUARTER + - name: session_end + meta: + dimension: + type: timestamp + time_intervals: + - DAY + - MONTH + - QUARTER + - name: duration + meta: + dimension: + type: number + sql: EXTRACT(DAY FROM ${session_end_day} - ${session_start_day}) +``` + +In this example, `${session_start_day}` and `${session_end_day}` reference the `DAY` time interval versions of the `session_start` and `session_end` dimensions. + ## Groups You can group your dimensions and metrics in the sidebar using the `groups` parameter. From 37b521bac6d8a5921841aad193b5f6e5c9b6ee4f Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:08:15 +0000 Subject: [PATCH 2/8] Update references/dimensions.mdx --- references/dimensions.mdx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/references/dimensions.mdx b/references/dimensions.mdx index 391ffd71..6b608682 100644 --- a/references/dimensions.mdx +++ b/references/dimensions.mdx @@ -787,3 +787,34 @@ models: type: max sql: ${version} ``` + +### Referencing time intervals in additional dimensions + +You can reference time interval dimensions within additional dimensions. This is useful for creating custom logic based on specific time intervals. + +For example, you can create a tier based on whether a specific time interval has a value: + +```yaml + - name: session_start + meta: + dimension: + type: timestamp + time_intervals: + - DAY_OF_WEEK_NAME + - WEEK + - MONTH + - RAW + - DAY + - HOUR_OF_DAY_NUM + - QUARTER + additional_dimensions: + extra_session_start_tier: + type: string + sql: | + CASE + WHEN ${session_start_month} IS NOT NULL THEN 'month' + ELSE 'else' + END +``` + +In this example, the additional dimension `extra_session_start_tier` references `${session_start_month}`, which is the `MONTH` time interval of the `session_start` dimension. From e1b3270ecdcadb43ef3a6961644e24d0a9f9f153 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:08:35 +0000 Subject: [PATCH 3/8] Update references/metrics.mdx --- references/metrics.mdx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/references/metrics.mdx b/references/metrics.mdx index 024d8452..fd2fcc81 100644 --- a/references/metrics.mdx +++ b/references/metrics.mdx @@ -590,6 +590,22 @@ The list of fields must be made of dimension names (no metrics) from the base ta The order that the fields are listed in `show_underlying_values` is the order that they'll appear in on the `view underlying data` table. +### Referencing time intervals in show underlying values + +You can reference specific time intervals of dimensions in the `show_underlying_values` list. When a dimension has time intervals defined, you can reference the specific interval by appending the interval name to the dimension name (e.g., `session_start_month`, `session_end_quarter`). + +```yaml + count: + type: count + label: Count + sql: '1' + show_underlying_values: + - session_start_month + - session_end_quarter +``` + +In this example, `session_start_month` and `session_end_quarter` reference the `MONTH` and `QUARTER` time intervals of the `session_start` and `session_end` dimensions respectively. + ## Groups You can group your dimensions and metrics in the sidebar using the `groups` parameter. From 0b0a1c43b9461b73e34b2a25fa492d8c6d8e4ad8 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:08:55 +0000 Subject: [PATCH 4/8] Update references/metrics.mdx --- references/metrics.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/references/metrics.mdx b/references/metrics.mdx index fd2fcc81..e07384c8 100644 --- a/references/metrics.mdx +++ b/references/metrics.mdx @@ -767,6 +767,21 @@ models: - web_sessions.is_bot_user: false ``` +### Referencing time intervals in filters + +You can reference specific time intervals of dimensions in metric filters. When a dimension has time intervals defined, you can filter on the specific interval by appending the interval name to the dimension name (e.g., `session_start_day`). + +```yaml + count: + type: count + label: Count + sql: '1' + filters: + - session_start_day: "!null" +``` + +In this example, the filter checks that `session_start_day` (the `DAY` time interval of the `session_start` dimension) is not null. + ### Metric filters cannot be used with non-aggregate metrics You can't use filters with non-aggregate metric types. Instead, if your non-aggregate metrics are referencing aggregate metric types, you need to apply metric filters to the aggregate metrics. From 78fc0d7ba3eb80a3533dc47f5155535daedf4444 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:09:27 +0000 Subject: [PATCH 5/8] Update references/metrics.mdx --- references/metrics.mdx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/references/metrics.mdx b/references/metrics.mdx index e07384c8..8d22c803 100644 --- a/references/metrics.mdx +++ b/references/metrics.mdx @@ -536,6 +536,18 @@ metrics: sql: 'IF(${subscriptions.is_active}, ${user_id}, NULL)' ``` +### Referencing time intervals in custom SQL + +You can reference specific time intervals of dimensions in custom SQL for aggregate metrics. When a dimension has time intervals defined, you can reference the specific interval by appending the interval name to the dimension name. + +```yaml + max_month: + type: max + sql: ${session_start_month} +``` + +In this example, the metric references `${session_start_month}`, which is the `MONTH` time interval of the `session_start` dimension. This allows you to perform aggregations on specific time interval versions of your dimensions. + ## Using custom SQL in non-aggregate metrics In non-aggregate metrics, you can reference any other metric from the given model and any joined models. You **can’t reference other dimensions.** From 028538b6f5d71e9070e703abff1d05a020728ff8 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:20:46 +0000 Subject: [PATCH 6/8] Update references/dimensions.mdx --- references/dimensions.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/references/dimensions.mdx b/references/dimensions.mdx index 6b608682..95325876 100644 --- a/references/dimensions.mdx +++ b/references/dimensions.mdx @@ -418,10 +418,10 @@ You can set custom versions of time intervals by using additional dimensions and You can reference specific time intervals of a dimension in other dimensions. When you define time intervals for a dimension (like `session_start`), Lightdash creates separate dimensions for each interval (e.g., `session_start_day`, `session_start_month`). You can reference these in custom SQL for other dimensions. -For example, if you have a `session_start` dimension with time intervals defined, you can calculate the duration between two dates using the `DAY` interval: +For example, if you have a `user_created_at` dimension with time intervals defined, you can calculate the duration between two dates using the `DAY` interval: ```yaml - - name: session_start + - name: user_created_at meta: dimension: type: timestamp @@ -433,7 +433,7 @@ For example, if you have a `session_start` dimension with time intervals defined - DAY - HOUR_OF_DAY_NUM - QUARTER - - name: session_end + - name: first_purchase_at meta: dimension: type: timestamp @@ -445,10 +445,10 @@ For example, if you have a `session_start` dimension with time intervals defined meta: dimension: type: number - sql: EXTRACT(DAY FROM ${session_end_day} - ${session_start_day}) + sql: EXTRACT(DAY FROM ${first_purchase_at_day} - ${user_created_at_day}) ``` -In this example, `${session_start_day}` and `${session_end_day}` reference the `DAY` time interval versions of the `session_start` and `session_end` dimensions. +In this example, `${user_created_at_day}` and `${first_purchase_at_day}` reference the `DAY` time interval versions of the `user_created_at` and `first_purchase_at` dimensions. ## Groups From d131a95640538649819a2419819cc9b6213e9826 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:20:57 +0000 Subject: [PATCH 7/8] Update references/metrics.mdx --- references/metrics.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/references/metrics.mdx b/references/metrics.mdx index 8d22c803..91abe1a1 100644 --- a/references/metrics.mdx +++ b/references/metrics.mdx @@ -609,8 +609,6 @@ You can reference specific time intervals of dimensions in the `show_underlying_ ```yaml count: type: count - label: Count - sql: '1' show_underlying_values: - session_start_month - session_end_quarter From d77b08d04073b6b09e8c0d7f9f73db3615fc064d Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:20:59 +0000 Subject: [PATCH 8/8] Update references/metrics.mdx --- references/metrics.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/references/metrics.mdx b/references/metrics.mdx index 91abe1a1..613fa194 100644 --- a/references/metrics.mdx +++ b/references/metrics.mdx @@ -784,8 +784,6 @@ You can reference specific time intervals of dimensions in metric filters. When ```yaml count: type: count - label: Count - sql: '1' filters: - session_start_day: "!null" ```