diff --git a/guides/using-parameters.mdx b/guides/using-parameters.mdx index 6853a42..2db900c 100644 --- a/guides/using-parameters.mdx +++ b/guides/using-parameters.mdx @@ -64,7 +64,11 @@ Both syntaxes are equivalent and can be used interchangeably. ## How to define parameters -Parameters are defined in your `lightdash.config.yml` file. Here's an example of how to define parameters: +Parameters can be defined at two different levels in your Lightdash project: + +### Project-level parameters + +Project-level parameters are defined in your `lightdash.config.yml` file and are available across your entire project. Here's an example: ```yaml parameters: @@ -98,7 +102,30 @@ parameters: dimension: "department" ``` -For a complete reference of parameter properties and options, see the [lightdash.config.yml reference](/references/lightdash-config-yml#parameters-configuration). +For a complete reference of project-level parameter properties and options, see the [lightdash.config.yml reference](/references/lightdash-config-yml#parameters-configuration). + +### Model-level parameters + +Model-level parameters are defined within individual model YAML files in your dbt project and are scoped to the model where they are defined. These parameters are defined in the `meta.parameters` section of your model configuration: + +```yaml +models: + - name: orders + meta: + parameters: + date_range: + label: "Date Range" + description: "Filter data by date range" + options: + - "2023-01-01" + - "2022-01-01" + - "2021-01-01" + default: "2023-01-01" +``` + +Model-level parameters offer the same configuration options as project-level parameters but provide better encapsulation and organization by keeping parameters close to where they're used. + +For a complete reference of model-level parameter properties and options, see the [tables reference](/references/tables#parameters-configuration). ## Examples of using parameters diff --git a/references/tables.mdx b/references/tables.mdx index 8a92b58..44bfb68 100644 --- a/references/tables.mdx +++ b/references/tables.mdx @@ -70,7 +70,8 @@ models: | [required_attributes](#required-attributes) | object | Limits access to users with those attributes. [Read about user attributes](/references/user-attributes) | | group_details | object | Describes the groups for dimensions and metrics | | [default_filters](#default-filters) | array | Dimension filters that will be applied when no other filter on those dimension exists. [Read about `default_filters`](#default-filters) | -| [explores](#explores) | object | Allows you to define multiple table explores in Lightdash from a single dbt model. +| [explores](#explores) | object | Allows you to define multiple table explores in Lightdash from a single dbt model. | +| [parameters](#parameters-configuration) | object | Model-level parameters that can be referenced in SQL properties. [Read about parameters](#parameters-configuration) | ### Adding a new dbt model @@ -338,6 +339,69 @@ Using a properly defined primary key helps Lightdash optimize queries and provid | is [boolean] | Is complete is true | is_complete: "true" | | is not [boolean] | Is complete is false or null | is_complete: "\!true" | +## Parameters configuration + +The `parameters` section allows you to define model-level parameters that can be referenced in various parts of your model's SQL properties. These parameters are scoped to the specific model where they're defined. + +```yaml +models: + - name: orders + meta: + parameters: + region: + label: "Region" + description: "Filter data by region" + options: + - "EMEA" + - "AMER" + - "APAC" + default: ["EMEA", "AMER"] + multiple: true + department: + label: "Department" + description: "Filter data by department" + options_from_dimension: + model: "employees" + dimension: "department" +``` + +Each parameter is defined as a key-value pair where the key is the parameter name (must be alphanumeric with underscores or hyphens) and the value is an object with the following properties: + +| Property | Required | Value | Description | +| :----------------------- | :------- | :------------------------- | :---------- | +| `label` | Yes | string | A user-friendly label for the parameter as it will be displayed in the UI. | +| `description` | No | string | A description of the parameter. | +| `options` | No | Array of strings | A list of possible values for the parameter. | +| `default` | No | string or Array of strings | The default value(s) for the parameter. | +| `multiple` | No | boolean | Whether the parameter input will be a multi-select. | +| `allow_custom_values` | No | boolean | Whether users can input custom values beyond predefined options. | +| `options_from_dimension` | No | Object | Get parameter options from a dimension in a model. Requires `model` and `dimension` arguments (see below).| + +If using `options_from_dimension`, the object requires the following properties: + +| Property | Required | Value | Description | +| :---------- | :------- | :----- | :---------------------------------- | +| `model` | Yes | string | The model containing the dimension. | +| `dimension` | Yes | string | The dimension to get options from. | + +### Using model-level parameters + +Model-level parameters can be referenced in your model's SQL using the syntax `${lightdash.parameters.parameter_name}` or the shorter alias `${ld.parameters.parameter_name}`. + +For example, to reference a parameter named `region` in a dimension: + +```yaml +${lightdash.parameters.region} +``` + +Or using the shorter alias: + +```yaml +${ld.parameters.region} +``` + +See the [Parameters guide](/guides/using-parameters) for more examples and information on how to use parameters. + ## Explores You can define multiple table explores from a single table using the `explores` config. This will allow you to list the same dbt model multiple times in the list of Tables in Lightdash. You can use it to show different versions of a table, join different tables to the base table, customize table visibility, etc.