Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b32d600

Browse files
authored
Merge pull request #144 from lightdash/add-number-type-to-parameters-docs
docs: add number type to parameters
2 parents c082aa2 + a6c14b8 commit b32d600

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

‎guides/using-parameters.mdx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ Parameters are variables that you can define once and reference in multiple plac
2525
- Allow non-technical users to customize queries without writing SQL
2626
- Save parameter values at the chart and dashboard level
2727

28-
For example, you might define a `region` parameter that users can set to filter data by different geographic regions, or a `date_range` parameter that allows users to select different time periods for analysis.
28+
For example, you might define a `region` parameter that users can set to filter data by different geographic regions, a `date_range` parameter that allows users to select different time periods for analysis, or a `min_revenue` parameter with numeric values that allows users to set revenue thresholds for analysis.
29+
30+
<Info>
31+
**Parameter Types**: Parameters support both string and number values. You can use strings (like `"EMEA"` or `"2023年01月01日"`) or numbers (like `1000` or `5000`) as parameter options.
32+
</Info>
2933

3034
## Where can you reference parameters?
3135

@@ -123,6 +127,17 @@ parameters:
123127
default: ["EMEA", "AMER"]
124128
multiple: true
125129

130+
# Parameter with number type
131+
min_revenue:
132+
label: "Minimum Revenue"
133+
description: "Filter for minimum revenue threshold"
134+
type: "number"
135+
options:
136+
- 1000
137+
- 5000
138+
- 10000
139+
default: 5000
140+
126141
# Parameter with options from a dimension
127142
department:
128143
label: "Department"
@@ -183,7 +198,24 @@ models:
183198

184199
In this example, the `filtered_revenue` dimension will only show revenue for the regions selected in the `region` parameter.
185200

186-
### Example 2: Using parameters in table joins
201+
### Example 2: Using numeric parameters in dimension SQL
202+
203+
You can reference numeric parameters directly without casting:
204+
205+
```yaml
206+
models:
207+
- name: orders
208+
columns:
209+
- name: high_value_orders
210+
meta:
211+
dimension:
212+
type: boolean
213+
sql: ${TABLE}.revenue >= ${lightdash.parameters.min_revenue}
214+
```
215+
216+
In this example, the `high_value_orders` dimension will be true for orders with revenue greater than or equal to the numeric `min_revenue` parameter value.
217+
218+
### Example 3: Using parameters in table joins
187219

188220
You can use parameters in the SQL_ON clause of a table join. This includes both project-level parameters and model-level parameters from the joined table:
189221

@@ -288,9 +320,10 @@ SELECT
288320
FROM orders
289321
WHERE region IN (${lightdash.parameters.region})
290322
AND order_date >= ${lightdash.parameters.date_range}
323+
AND revenue >= ${lightdash.parameters.min_revenue}
291324
```
292325

293-
This query will filter orders by the regions selected in the `region` parameter and by the date selected in the `date_range` parameter.
326+
This query will filter orders by the regions selected in the `region` parameter, by the date selected in the `date_range` parameter, and by orders with revenue greater than or equal to the numeric `min_revenue` parameter.
294327

295328
## Saving parameter values at chart and dashboard levels
296329

‎references/lightdash-config-yml.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ parameters:
136136
- "APAC"
137137
default: ["EMEA", "AMER"]
138138
multiple: true
139+
min_revenue:
140+
label: "Minimum Revenue"
141+
description: "Filter for minimum revenue threshold"
142+
type: "number"
143+
options:
144+
- 1000
145+
- 5000
146+
- 10000
147+
default: 5000
139148
department:
140149
label: "Department"
141150
description: "Filter data by department"
@@ -150,8 +159,9 @@ Each parameter is defined as a key-value pair where the key is the parameter nam
150159
| :----------------------- | :------- | :------------------------- | :---------- |
151160
| `label` | Yes | string | A user-friendly label for the parameter as it will be displayed in the UI. |
152161
| `description` | No | string | A description of the parameter. |
153-
| `options` | No | Array of strings | A list of possible values for the parameter. |
154-
| `default` | No | string or Array of strings | The default value(s) for the parameter. |
162+
| `type` | No | "string" or "number" | The type of the parameter. Defaults to "string" if not specified. |
163+
| `options` | No | Array of strings or numbers | A list of possible values for the parameter. |
164+
| `default` | No | string, number, or Array of strings/numbers | The default value(s) for the parameter. |
155165
| `multiple` | No | boolean | Whether the parameter input will be a multi-select. |
156166
| `allow_custom_values` | No | boolean | Whether users can input custom values beyond predefined options. |
157167
| `options_from_dimension` | No | Object | Get parameter options from a dimension in a model. Requires `model` and `dimension` arguments (see below).|

‎references/tables.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,15 @@ models:
357357
- "APAC"
358358
default: ["EMEA", "AMER"]
359359
multiple: true
360+
min_order_value:
361+
label: "Minimum Order Value"
362+
description: "Filter for minimum order value"
363+
type: "number"
364+
options:
365+
- 100
366+
- 500
367+
- 1000
368+
default: 500
360369
department:
361370
label: "Department"
362371
description: "Filter data by department"
@@ -371,8 +380,9 @@ Each parameter is defined as a key-value pair where the key is the parameter nam
371380
| :----------------------- | :------- | :------------------------- | :---------- |
372381
| `label` | Yes | string | A user-friendly label for the parameter as it will be displayed in the UI. |
373382
| `description` | No | string | A description of the parameter. |
374-
| `options` | No | Array of strings | A list of possible values for the parameter. |
375-
| `default` | No | string or Array of strings | The default value(s) for the parameter. |
383+
| `type` | No | "string" or "number" | The type of the parameter. Defaults to "string" if not specified. |
384+
| `options` | No | Array of strings or numbers | A list of possible values for the parameter. |
385+
| `default` | No | string, number, or Array of strings/numbers | The default value(s) for the parameter. |
376386
| `multiple` | No | boolean | Whether the parameter input will be a multi-select. |
377387
| `allow_custom_values` | No | boolean | Whether users can input custom values beyond predefined options. |
378388
| `options_from_dimension` | No | Object | Get parameter options from a dimension in a model. Requires `model` and `dimension` arguments (see below).|

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /