lightdash.config.yml file and can be referenced in various parts of your Lightdash project.
If you’re new to lightdash.config.yml, check out our getting started guide to learn how to create and set up this file.
What are parameters?
Parameters are variables that you can define once and reference in multiple places throughout your Lightdash project. They allow you to:- Create dynamic filters that users can change at runtime
- Make your SQL more reusable and maintainable
- Allow non-technical users to customize queries without writing SQL
- Save parameter values at the chart and dashboard level
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.
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.Where can you use parameters?
Parameters can be referenced in many places throughout your Lightdash project:- Dimension SQL: Use parameters in the SQL definition of a dimension
- Metric SQL: Use parameters in the SQL definition of a metric
- Table SQL: Use parameters in sql_from and sql_filter definitions
- Table Joins: Use parameters in join conditions
- SQL Runner: Use parameters in the SQL Runner query
- Table Calculations: Use parameters in table calculations
- Additional Dimensions: Use parameters in the SQL definition of an additional dimension
- Custom Dimensions: Use parameters in custom dimension definitions
Parameter types
Parameters in Lightdash support different data types to help you work with various kinds of data. By default, all parameters are treated as strings, but you can convert them to other types as needed.Supported parameter types
Lightdash officially supports the following parameter types:- String (default): Text values
- Number: Numeric values (integers and decimals)
Type conversion workarounds
While not officially supported yet, you can work around for other data types via SQL type casting. To convert a parameter to a specific type, use the:: syntax followed by the type name:
The type conversion happens at the SQL level, so the available types depend on your database system (PostgreSQL, BigQuery, Snowflake, etc.). Common types like
integer, numeric, date, timestamp, and boolean are supported across most databases.Date conversion
As a workaround, you can use::date for dates or ::timestamp for datetime values:
Boolean conversion
As a workaround, you can use::boolean to convert string values like “true”/“false” to boolean:
Other type conversions
You can use any SQL type conversion that your database supports:How to reference parameters in SQL
Project-level parameters
To reference project-level parameters in SQL, use the following syntax:region:
Model-level parameters
To reference model-level parameters in SQL, you need to include the model name:region from the orders model:
Using the shorter alias
You can also use the shorter aliasld instead of lightdash:
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 yourlightdash.config.yml file and are available across your entire project. Here’s an example:
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 themeta.parameters section of your model configuration:
Examples of using parameters
Let’s look at some examples of how to use parameters in different parts of your Lightdash project.In dimension SQL
You can reference parameters in the SQL definition of a dimension:filtered_revenue dimension will only show revenue for the regions selected in the region parameter.
In numeric dimension SQL
You can reference numeric parameters directly without casting:high_value_orders dimension will be true for orders with revenue greater than or equal to the numeric min_revenue parameter value.
In metric SQL
You can reference parameters in the SQL definition of a metric:avg_distance_unit_param metric will return an average of the race distance in miles when the unit parameter is set to Miles and Kilometers when it gets set to Kilometers.
In table joins
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:region parameter.
You can also reference model-level parameters from joined tables:
customer_status defined in the customers model. This allows you to dynamically filter the joined data based on parameters specific to the joined table.
In table calculations
You can reference parameters in table calculations:date_range parameter.
In additional dimensions
You can use parameters in custom dimension definitions:date_range parameter.
In SQL Runner
Parameters can also be used in SQL Runner queries: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.
Model parameters from joined tables in dimensions
When working with joined tables, you can reference model-level parameters from the joined table in your dimension definitions:filtered_customer_revenue dimension uses a model-level parameter target_segment from the joined customers model to conditionally show revenue.
Saving parameter values
Parameter values can be saved at both the chart and dashboard levels.Saving values in charts
When you create a chart using parameters, you can save the specific parameter values with the chart. This means that when someone views the chart, they’ll see the data filtered according to the saved parameter values. To save parameter values with a chart:- Create or edit a chart
- Set the parameter values as desired
- Save the chart
Saving values in dashboards
You can also save parameter values at the dashboard level, which allows you to create dashboards with consistent parameter values across all charts. To save parameter values in a dashboard:- Create or edit a dashboard
- Add charts to the dashboard
- Set the parameter values as desired
- Save the dashboard
Best practices for using parameters
Here are some best practices to follow when using parameters:- Use descriptive names: Choose parameter names that clearly indicate their purpose
- Provide default values: Set default values for parameters to ensure queries work even if users don’t set parameter values
- Add descriptions: Include clear descriptions for parameters to help users understand their purpose
- Consider using options_from_dimension: For parameters that should match values in your data, use
options_from_dimensionto dynamically populate options - Consider performance: Be mindful of how parameters affect query performance, especially with large datasets