How to Avoid Double Application of Time Filter (Dashboard & Jinja) in Superset? #35233
Replies: 2 comments
-
Superset always applies the dashboard time filter to queries with a temporal column—there's no setting to disable this at the chart or dataset level (source). To avoid double filtering when you use custom Jinja logic (like from_dttm/to_dttm) in a virtual dataset, use the Jinja macros get_time_filter or filter_values with remove_filter=True. This tells Superset to treat the filter as already handled, so it won't apply it again in the outer query (source, discussion). Example: {% set time_filter = get_time_filter('your_column', remove_filter=True) %}
WHERE your_column BETWEEN {{ time_filter.from_expr }} AND {{ time_filter.to_expr }} or {% set vals = filter_values('your_column', remove_filter=True) %} Be aware: if you use nested virtual datasets or the dataset() macro, there's a known bug where the removal state might not propagate, causing double filtering anyway. To avoid this, keep your filter removal logic at the top level of your virtual dataset (source). If you need to filter on columns only used in subqueries, add them as calculated columns in your dataset so they can be mapped to dashboard filters (discussion). For multiple independent time filters, use custom field value filters and reference them by name in your Jinja SQL, since Superset only supports one main time filter per dashboard (discussion, issue). To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
I am not sure if i understand correctly but you should be able to remove the chart from the filters scope, there is a tab for it in add/edit filters modal |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Question:
In Superset, when I have a dataset with a temporal column and use a chart in a dashboard, the dashboard’s time filter is automatically applied to queries for that dataset.
However, I also need to use custom Jinja logic (using from_dttm/to_dttm) inside my virtual dataset SQL for advanced time filtering. When I do this, it seems the same time filter is applied twice: once by Superset automatically (because of the temporal column and dashboard filter), and once in my own SQL via Jinja.
Is there a recommended way to avoid this double-filtering?
Any guidance from the community would be appreciated!
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions