Query filters

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
You can have several filters on different columns in a single query.

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
In case your Data Source doesn't allow double colons (::) in the alias, you can use __filter and __multiFilter instead.
Since you're adding filter as an alias, don't forget to enclose it in double quotes! For example, SELECT country AS "country::filter" FROM my_table.

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:

 
If you download the dataset, you will have all the data, and not only the filtered columns, the filter is only representational!

Here is an example of a multi-filter, where you can select more than one value:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.111.193