Link filters to queries on Superset
Asked Answered
S

2

5

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.

Sarette answered 19/10, 2018 at 12:51 Comment(0)
C
6

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.

Carolinecarolingian answered 10/2, 2021 at 18:0 Comment(0)
A
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

Alameda answered 16/2, 2019 at 18:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.