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
{{ message }}
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
description: 'Total estimated revenue in GBP based on forecasting done by the finance team.'
51
51
meta:
52
52
dimension:
53
-
type: string
53
+
type: number
54
54
label: 'Total revenue' # this is the label you'll see in Lightdash
55
55
description: 'My custom description' # you can override the description you'll see in Lightdash here
56
56
sql: 'IF(${TABLE}.revenue_gbp_total_est = NULL, 0, ${registered_user_email})' # custom SQL applied to the column from dbt used to define the dimension
57
57
hidden: false
58
-
round: 2
59
-
format: 'gbp'
58
+
format: '[$£]#,##0.00' # GBP rounded to two decimal points
60
59
groups: ['finance']
61
60
- name: forecast_date
62
61
description: 'Date of the forecasting.'
@@ -76,11 +75,16 @@ models:
76
75
dimension:
77
76
type: date
78
77
additional_dimensions:
79
-
dimension_name_one:
78
+
day_of_week_num:
80
79
type: number
81
-
label: 'Day of Week'
80
+
label: 'Day of Week (number)'
82
81
sql: 'day_of_week(${date})'
83
-
dimension_name_two:
82
+
day_of_week_day:
83
+
type: date
84
+
label: 'Day of Week (day)'
85
+
sql: ${date}
86
+
format: 'dddd'
87
+
is_weekday_or_weekend:
84
88
type: boolean
85
89
label: 'Weekday or Weekend'
86
90
sql: "case when day_of_week(${date}) < 5 then 'weekday' else 'weekend' end"
@@ -96,9 +100,7 @@ All the properties you can customize:
96
100
| sql | No | string | Custom SQL applied to the column used to define the dimension. |
97
101
| [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', 'YEAR']` for dates and `['RAW', 'DAY', 'WEEK', 'MONTH', 'YEAR']` for timestamps; if you want no time intervals set `'OFF'`. |
98
102
| 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. |
99
-
| round | No | number | Rounds a number to a specified number of digits |
100
-
| [format](#format) | No | string | This option will format the output value on the result table and CSV export. Currently supports one of the following: `['km', 'mi', 'usd', 'gbp', 'eur', 'percent', 'id']` |
101
-
| [compact](#compact-values) | 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']` |
103
+
| [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.` |
102
104
| [groups](#groups) | No | string or string[] | If you set this property, the dimension will be grouped in the sidebar with other dimensions with the same group label. |
103
105
| [urls](#urls) | No | Array of { url, label } | Adding urls to a dimension allows your users to click dimension values in the UI and take actions, like opening an external tool with a url, or open at a website. You can use liquid templates to customise the link based on the value of the dimension. |
104
106
| [required_attributes](#required-attributes) | No | Object with { user_attribute, value } | Limits access to users with those attributes |
@@ -185,7 +187,80 @@ and it will stay on multiple lines
185
187
186
188
You can also use dbt docs blocks in descriptions, [more on that here](/guides/cli/how-to-auto-generate-schema-files#using-doc-blocks-to-build-better-yml-files).
187
189
188
-
## Compact values
190
+
## Format
191
+
192
+
You can use the `format` parameter to have your dimensions show in a particular format in Lightdash. Lightdash supports spreadsheet-style format expressions for all dimension types.
193
+
194
+
To help you build your format expression, we recommend using https://customformats.com/.
195
+
196
+
```yaml
197
+
- name: us_revenue
198
+
meta:
199
+
dimension:
200
+
type: number
201
+
description: 'Revenue in USD, with two decimal places, compacted to thousands'
202
+
format: '$#,##0.00," K"' # 505,430 will appear as '$505.43 K'
203
+
additional_dimensions:
204
+
percent_of_global_revenue:
205
+
type: number
206
+
description: 'Percent of total global revenue coming from US revenue.'
207
+
sql: ${us_revenue} / ${global_revenue}
208
+
format: '0.00%' # 0.67895243 will appear as '67.89%
209
+
```
210
+
211
+
Example format expressions:
212
+
213
+
| Raw Value | Formatted value | Format expression |
<summary>(Legacy) format, round, and compact options</summary>
226
+
227
+
Spreadsheet-style format expressions are the recommended way of adding formatting to your metrics in Lightdash. There are legacy formatting options, listed below, which are less flexible than the spreadsheet-style formatting.
228
+
229
+
:::info
230
+
231
+
If you use both legacy and spreadsheet-style formatting options for a single dimension, Lightdash will ignore the legacy `format`, `compact`, and `round` options and only apply the spreadsheet-style formatting expression.
232
+
233
+
:::
234
+
235
+
#### Format (legacy)
236
+
237
+
```yaml
238
+
version: 2
239
+
240
+
models:
241
+
- name: sales_stats
242
+
columns:
243
+
- name: revenue
244
+
description: 'Total estimated revenue in GBP based on forecasting done by the finance team.'
245
+
meta:
246
+
dimension:
247
+
format: 'gbp'
248
+
```
249
+
250
+
These are the options:
251
+
252
+
| Option | Equivalent format expression | Description | Raw value | Displayed value |
| km | '#,##0.00" km"' | Adds the suffix `km` to your value | 10 | 10 km |
255
+
| mi | '#,##0.00" mi"' | Adds the suffix `mile` to your value | 10 | 10 mi |
256
+
| usd | '[$]#,##0.00' | Adds the `$` symbol to your number value | 10 | $10.00 |
257
+
| gbp | '[$£]#,##0.00' | Adds the `£` symbol to your number value | 10 | £10.00 |
258
+
| eur | '[$€]#,##0.00' | Adds the `€` symbol to your number value | 10 | €10.00 |
259
+
| jpy | '[$¥]#,##0.00' | Adds the `¥` symbol to your number value | 10 | ¥10 |
260
+
| percent | '#,##0.00%' | Adds the `%` symbol and multiplies your value by 100 | 0.1 | %10 |
261
+
| id | '0' | Removes commas and spaces from number or string types so that they appear like IDs. | 12389572 | 12389572 |
262
+
263
+
#### Compact (legacy)
189
264
190
265
You can compact values in your YAML. For example, if I wanted all of my revenue values to be shown in thousands (e.g. `1,500` appears as `1.50K`), then I would write something like this in my .yml:
191
266
@@ -197,15 +272,32 @@ You can compact values in your YAML. For example, if I wanted all of my revenue
[Formatting](#format) added to a date or timestamp dimension will be applied to all of the time intervals for that dimension. If you want to apply different formats for different time intervals, we recommend creating [additional dimensions](#additional-dimensions) for time intervals where you want to customize the format.
320
+
321
+
:::
322
+
225
323
### By default, the time intervals we use are:
226
324
227
325
**Date**: ['DAY', 'WEEK', 'MONTH', 'YEAR']
@@ -295,35 +393,6 @@ You can see all of the interval options for date and timestamp fields below.
295
393
| MONTH_NAME | Month name | String | March |
296
394
| QUARTER_NAME | Quarter name | String | Q3 |
297
395
298
-
## Format
299
-
300
-
You can use the `format` parameter to have your dimensions show in a particular format in Lightdash.
301
-
302
-
```yaml
303
-
- name: revenue
304
-
description: 'Timestamp when the user was created.'
305
-
meta:
306
-
dimension:
307
-
format: 'usd'
308
-
metrics:
309
-
total_revenue:
310
-
type: sum
311
-
format: 'usd'
312
-
```
313
-
314
-
These are the options:
315
-
316
-
| Option | Description | Raw value | Displayed value |
0 commit comments