Skip to content

Commit

Permalink
Added additional text, some spell check fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Vagie authored and Daniel Vagie committed Sep 16, 2024
1 parent ffd8dd2 commit 54276d5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions docs/app/visualization/Dashboards.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ can be filtered on, sorted by, and/or used to categorize data.

<img alt="Dashboard - Calculated Column" src="https://ganymede-bio.mo.cloudinary.net/dashboard/Calculated_Column20230415.png" />

## 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 %}
Expand All @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit 54276d5

Please sign in to comment.