4

I have created a visualisation in Apache Superset based on a Saved Query. How can I update the query based on the values filtered within a Filter Box?

I have experimented with Jinja and managed to pass hardcoded variables to my query through the template parameters. Now I just need to connect Jinja to the Filter Box such that the values are obtained through the filter rather than hard coded.

TylerH
  • 20,799
  • 66
  • 75
  • 101
ganninu93
  • 1,551
  • 14
  • 24

2 Answers2

5

I discovered that this is possible using the filter_values function that is added to the Jinja context via this file: https://github.com/apache/superset/blob/master/superset/jinja_context.py

The example in that file shows how one can build a templated query that pulls values from a filter box:

SELECT action, count(*) as times
FROM logs
WHERE action in ( {{ "'" + "','".join(filter_values('action_type')) + "'" }} )
GROUP BY action

So if you have a filter box for selecting values for action_type, those values will be returned by filter_values.

Alan LaMielle
  • 401
  • 4
  • 12
1

The column name used in the filter should be the same in another table also. Have you tried it? If column names are different then create a materialized view with the changed column name or rename the column in the table itself

SKM
  • 11
  • 1