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, or a date_range
parameter that allows users to select different time periods for analysis.
Where can you reference 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
How to reference parameters in SQL
To reference parameters in SQL, use the following syntax:region
:
How to define parameters
Parameters are defined in yourlightdash.config.yml
file. Here’s an example of how to define parameters:
Examples of using parameters
Let’s look at some examples of how to use parameters in different parts of your Lightdash project.Example 1: Using parameters 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.
Example 2: Using parameters in table joins
You can use parameters in the SQL_ON clause of a table join:region
parameter.
Example 3: Using parameters in table calculations
You can reference parameters in table calculations:date_range
parameter.
Example 4: Using parameters in additional dimensions
You can use parameters in custom dimension definitions:date_range
parameter.
Example 5: Using parameters in SQL Runner
Parameters can also be used in SQL Runner queries:region
parameter and by the date selected in the date_range
parameter.
Saving parameter values at chart and dashboard levels
Parameter values can be saved at both the chart and dashboard levels.Saving parameter 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 parameter 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_dimension
to dynamically populate options - Consider performance: Be mindful of how parameters affect query performance, especially with large datasets