GitHub user dosubot[bot] added a comment to the discussion: How to Avoid Double Application of Time Filter (Dashboard & Jinja) in Superset?
<!-- Answer --> 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](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/viz.py)). 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](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/jinja_context.py), [discussion](https://github.com/apache/superset/issues/34894)). Example: ```jinja {% 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 ```jinja {% 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](https://github.com/apache/superset/issues/34894)). 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](https://github.com/apache/superset/discussions/35171)). 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](https://github.com/apache/superset/discussions/33807), [issue](https://github.com/apache/superset/issues/33725)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/2167c9a6-4124-462b-a5aa-fef416ac5f0e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2167c9a6-4124-462b-a5aa-fef416ac5f0e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2167c9a6-4124-462b-a5aa-fef416ac5f0e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2167c9a6-4124-462b-a5aa-fef416ac5f0e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2167c9a6-4124-462b-a5aa-fef416ac5f0e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2167c9a6-4124-462b-a5aa-fef416ac5f0e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2167c9a6-4124-462b-a5aa-fef416ac5f0e?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)& nbsp;[](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/35233) GitHub link: https://github.com/apache/superset/discussions/35233#discussioncomment-14478318 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
