Redash query filtering using “cascade filters”

Alexey Shulzhenko
3 min readJun 6, 2021

Since I’m working as a Data Analyst, I am trying to optimize my daily routine workflow and always search for new tools. Some time ago I started using Redash as the main dashboard tool. It’s a simple tool, that allows me to compose dashboards and visualizations and do user management.

The only issue I had is related to the amount of data, I work with. Sometimes it’s very hard to optimize enough queries and maintain usability and all the required filters.

There are two main options, how can you dynamically filter data in Redash:

  1. Parameters
  2. Query filters

The difference between these two approaches is that the Parameter makes changes in the query itself, while the Filter only filtering query results. Obviously, parameters can easily make your query result smaller. And now let’s go through use cases for both types and then check how can we use both of them at the same time.

Parameter

In the documentation, you can find a detailed description of all parameter types and features. I just want to highlight how you can use it. For example, you need to filter only important countries from the list. To do that add

WHERE country IN ({{Country}})

And configure a filter in the UI by choosing the type (it can be either Dropdown List or Query Based Dropdown List) and ticking Allow multiple values checkbox and choosing suitable Quotation.

That’s all.
From now yure query results will contain only results from the countries you selected, but what if you want to do that same thing with Cities?
Of course, you may add another parameter containing the list of all cities in the world, and let the User select among them. It may lead to making your UI slow and laggy. Another option is Query Filter.

Query Filter

As I said before, the key difference is that Query Filters filtering data After the result has been fetched. It means that if you filtered data with the Country parameter — the resulting table will contain only cities, that are present in selected countries. Do you see what I mean?
Yes, we can do the following:
city AS "city::filter"

And now after running this query Redash automatically will add this filter to the panel with other filters.
And one more thing — there are types of filters: filter and multiFilter The first one creates a single choice dropdown, the second one allows you to pick multiple options.

For now, it is the only option, how you can create “cascade” filters in Redash, but this functionality is more than enough to deal with most cases.

Sources:

--

--