In addition to using filters in the traditional [created_at=daterange] fashion, filter values can be selected using [filter_name]. These types of direct replacement filters are a great way to substitute bits of sql directly into the query while allowing users to choose the value from the dashboard in the classic filter style.
There are a couple different ways a filter can be integrated into the query. Here are a few common examples.
To allow users to dynamically choose the columns they want selected in the query, first set up the filter with the available column options.
In the query, reference the filter using square parentheses like so:
Another common case is to use direct replacement filters to change part of a phrase.
This can be achieved by creating a ranged filter:
With the final implementation looking like:
Creating a null filter might look like:
The implementation and the generated sql would look like:
Aside from setting a default filter value directly on the dashboard, a default value can be set in a direct replacement filter directly in the query.
This default value will be used when no filter option is selected within the dashboard. This is helpful for direct replacement filters, where the SQL query can produce an error when no filter option is selected.
When implementing direct replacement filters in the queries, the pipe symbol '|' can used to define a filter default. The filter default is substituted when no filter value is selected on the dashboard. To specify a default, after the filter name include the pipe followed by the default value:
First, create the filter to be used in the query.
Next, use the pipe in the query to define the default value. When nothing is selected in the filer, the pipe notation takes seniority:
However, when a filter option, such as Network, is selected in the dashboard, the filter option will be replaced into the query:
Filter casing is case-sensitive for direct replacement filters. A filter within the SQL query with a lower-cased first letter will insert the original casing of the filter value. However, if the first letter is upper-cased, the inserted filter value will have an upper-cased first letter.
Direct replacement filters can be used in chart titles to help users identify the filters currently applied to the chart at the dashboard level. Here, filter casing is helpful to maintain properly cased titles.