You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: references/dimensions.mdx
+61-3Lines changed: 61 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -157,7 +157,7 @@ The table below shows all the dimension properties you can customize:
157
157
| [type](#type) | No | Dimension type | The dimension type is automatically pulled from your table schemas in Lightdash but you can override the type using this property. |
158
158
| [description](#description) | No | string | Description of the dimension in Lightdash. You can use this to override the description you have for the dimension in dbt. |
159
159
| sql | No | string | Custom SQL applied to the column used to define the dimension. |
160
-
| [time_intervals](#time-intervals) | No | 'default' or OFF or an array[] containing elements of [date](#date-options), [numeric](#numeric-options) or [string](#string-options) options| 'default' (or not setting the time_intervals property) will be converted into ['DAY', 'WEEK', 'MONTH', 'QUARTER', 'YEAR'] for dates and ['RAW', 'DAY', 'WEEK', 'MONTH', 'QUARTER', 'YEAR'] for timestamps; if you want no time intervals set 'OFF'. |
160
+
| [time_intervals](#time-intervals) | No | 'default' or OFF or an array[] containing elements of [date](#date-options), [numeric](#numeric-options), [string](#string-options) options, or [custom granularity](#using-custom-granularities) names | 'default' (or not setting the time_intervals property) will be converted into ['DAY', 'WEEK', 'MONTH', 'QUARTER', 'YEAR'] for dates and ['RAW', 'DAY', 'WEEK', 'MONTH', 'QUARTER', 'YEAR'] for timestamps; if you want no time intervals set 'OFF'. You can also include custom granularity names defined in `lightdash.config.yml`. |
161
161
| hidden | No | boolean | If set to true, the dimension is hidden from Lightdash. By default, this is set to false if you don't include this property. Hidden dimensions are also excluded from drilldowns (View underlying data). |
162
162
| [compact](#compact) | No | string | This option will compact the number value (e.g. 1,500 to 1.50K). Currently supports one of the following: ['thousands', 'millions', 'billions', 'trillions', 'kilobytes', 'megabytes', 'gigabytes', 'terabytes', 'petabytes', 'kibibytes', 'mebibytes', 'gibibytes', 'tebibytes', 'pebibytes'] |
163
163
| [format](#format) | No | string | This option will format the output value on the results table and CSV export. Supports spreadsheet-style formatting (e.g. #,##0.00). Use [this website](https://customformats.com) to help build your custom format. |
@@ -677,9 +677,67 @@ You can see all of the standard interval options for date and timestamp fields b
677
677
| QUARTER_NAME | Quarter name | String | Q3 |
678
678
679
679
680
-
### Custom time intervals
680
+
### Using custom granularities
681
681
682
-
You can set custom versions of time intervals by using additional dimensions and groups. Here's an example of how that might look if you wanted to add `year_of_week_iso` to your drop down list for the `delivery_date` dimension. Note that by definiting the `groups:` option, we ensure that the new "Year of week" options is displayed as expected.
682
+
You can define reusable custom time granularities in your `lightdash.config.yml` file and reference them in the `time_intervals` array. Custom granularities appear in the date zoom dropdown alongside standard options.
683
+
684
+
**Step 1**: Define custom granularities in `lightdash.config.yml`:
The `${COLUMN}` placeholder in the SQL expression is automatically replaced with the dimension's column SQL at runtime. Custom granularities also inherit `requiredAttributes` and `anyAttributes` from the parent dimension.
733
+
734
+
<Info>
735
+
See [lightdash.config.yml reference](/references/lightdash-config-yml#custom-granularities-configuration) for the full configuration options for custom granularities.
736
+
</Info>
737
+
738
+
### Custom time intervals with additional dimensions
739
+
740
+
You can also set custom versions of time intervals by using additional dimensions and groups. Here's an example of how that might look if you wanted to add `year_of_week_iso` to your drop down list for the `delivery_date` dimension. Note that by definiting the `groups:` option, we ensure that the new "Year of week" options is displayed as expected.
Copy file name to clipboardExpand all lines: references/lightdash-config-yml.mdx
+69Lines changed: 69 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,10 @@ parameters:
93
93
# Configuration for project-wide defaults
94
94
defaults:
95
95
# ...
96
+
97
+
# Configuration for custom date granularities
98
+
custom_granularities:
99
+
# ...
96
100
```
97
101
98
102
@@ -248,4 +252,69 @@ models:
248
252
249
253
<Info>
250
254
See [Tables reference](/references/tables#case-sensitive) for explore-level configuration and [Dimensions reference](/references/dimensions#case-sensitive) for dimension-level configuration.
255
+
</Info>
256
+
257
+
258
+
## Custom granularities configuration
259
+
260
+
The `custom_granularities` section allows you to define reusable custom time granularities that appear in the date zoom dropdown alongside standard options (Day, Week, Month, Quarter, Year). This is useful for business-specific time periods like fiscal quarters, Monday-to-Sunday weeks, or other custom date groupings.
sql: "EXTRACT(YEAR FROM ${COLUMN} + INTERVAL '1 month')"
273
+
```
274
+
275
+
Each custom granularity is defined as a key-value pair where the key is the granularity name (must be alphanumeric with underscores) and the value is an object with the following properties:
276
+
277
+
| Property | Required | Value | Description |
278
+
| :------- | :------- | :----- | :---------- |
279
+
| `label` | Yes | string | A user-friendly label for the granularity as it will be displayed in the date zoom dropdown. |
280
+
| `sql` | Yes | string | SQL expression that defines how to truncate/transform the date. Use `${COLUMN}` as a placeholder for the actual date column - it will be replaced with the column's SQL at runtime. |
281
+
282
+
### How custom granularities work
283
+
284
+
Custom granularities are defined at the project level in `lightdash.config.yml` and become available on date dimensions through the `time_intervals` property. The `${COLUMN}` template in the SQL expression is automatically replaced with the actual column SQL when generating queries.
285
+
286
+
**Example**: Define a fiscal quarter granularity and use it on a dimension:
The custom granularity `fiscal_quarter` will now appear in the date zoom dropdown for `order_date`, alongside the standard intervals.
307
+
308
+
<Info>
309
+
Custom granularities inherit `requiredAttributes` and `anyAttributes` from the parent dimension, so access controls are automatically applied.
310
+
</Info>
311
+
312
+
### Use cases
313
+
314
+
- **Fiscal calendars**: Define fiscal quarters or years that don't align with calendar quarters
315
+
- **Week start customization**: Create weeks that start on Monday or any other day
316
+
- **Custom periods**: Define business-specific time periods like "retail weeks" or "academic terms"
317
+
318
+
<Info>
319
+
See [Dimensions reference](/references/dimensions#time-intervals) for more information on configuring time intervals on dimensions, including how to reference custom granularities.
0 commit comments