diff --git a/docs/app/visualization/Dashboards.mdx b/docs/app/visualization/Dashboards.mdx index 78fcbbf4..88e4a5b3 100644 --- a/docs/app/visualization/Dashboards.mdx +++ b/docs/app/visualization/Dashboards.mdx @@ -101,16 +101,17 @@ can be filtered on, sorted by, and/or used to categorize data. Dashboard - Calculated Column -## Adding Jinja Templating to SQL Queries +## Adding Jinja Templates to SQL Queries -There are two ways to use Jinja templating in SQL queries: +There are two ways to use Jinja templates in SQL queries: -1. [Virtual Quaries](#adding-virtual-datasets) +1. [Virtual Queries](#adding-virtual-datasets) 2. Metrics -### Virtual Queries +### Example Using Virtual Queries -A virtual query can be constructed to use Jinja templating using: +An example virtual query that inherits inputs from a filter can be constructed to use Jinja +templates using: ```sql {% set variable_name = filter_values('some_column_name')[0] if filter_values('some_column_name') else 1 %} @@ -127,8 +128,11 @@ it always returns a list of selected values). The if statement checks to see a f selected on column `some_column_name` and returns 1 otherwise. This assigns a default value to the query so that the dataset can be created and not raise any errors if there are no active filtered values present on that column. A dataset will not be savable without the if statement. +After saving the query to a virtual dataset, any chart in a dashboard will have the Jinja template +automatically be rendered. -### Metrics + +### Examples Using Metrics Creating a chart, a line chart for instance, requires creating a metric on that variable. You can use filter values by either referencing the new column created in a virtual query or by making the metric as follows: @@ -150,11 +154,11 @@ Its important to make sure that you have a. For instance you have a filter defined in the dashboard named `My Filter` created on dataset `my_dataset` on column `some_column_name` where `some_column_name` is referenced in the Jinja template -3. The column name is not contained in the dataset you are using the Jinja templating in (unless you actually want your chart to be filtered as well) +3. The column name is not contained in the dataset you are using the Jinja template in (unless you actually want your chart to be filtered as well) 4. You may need to wrap your Jinja template in a CAST to convert to INT or NUMERIC if necessary 5. Other useful links for more detail or other use cases of Jinja: a. [From Preset website](https://preset.io/blog/intro-jinja-templating-apache-superset/) - b. [From Apche Superset website](https://superset.apache.org/docs/configuration/sql-templating/) + b. [From Apache Superset website](https://superset.apache.org/docs/configuration/sql-templating/) ## Editing dashboards