Redash offers a simple and handy way to add filters to results and visualizations.
Suppose you have a query that shows the distribution of Redash users per country, and you want to filter the result to see only a specific country (or countries) without having to rewrite the query (because you do need the whole output for all countries).
It is possible to do exactly that with filters!
Redash offers two types of filters:
- Single value filter: This means that you can select only a single value for the column you want to filter on
- Multi value filter: This means that you can have multiple values for the column you filter on
In order to enable filters, you have to follow a specific naming convention.
Inside your query, you must add an alias to the column you want to filter on:
- <column_name>::filter: For a single value filter
- <column_name>::multi-filter: For a multi-value filter
Let's look at an example. Suppose we have the following query:
SELECT type,
count(*) AS count_per_type
FROM visualizations
GROUP BY type
ORDER BY count_per_type
This query returns the visualization type and the number of visualizations of that specific type. Now, I would like to make the type filtered.
I can modify the query, as follows:
SELECT type AS "visualization_type::filter",
count(*) AS count_per_type
FROM visualizations
GROUP BY type
ORDER BY count_per_type
After you execute the query, you will be able to see the filter inside the results frame:
If you click on the filter, the slide menu with all the possible visualization_types will pop up, and you will be able to change the filter to another value.
The query is not being executed again; the filter is only on the end results:
Here is an example of a multi-filter, where you can select more than one value: