No way to pass Dashboard Filter values as dynamic parameters into Native SQL / Script Queries

Hi Insights team,

I’m building a dashboard where a Date range filter should drive the data behind several charts that need joins across multiple tables plus aggregation (grouping, sums, top-N with an “Other” bucket). A single-table Query Builder chart doesn’t cover this, so I need SQL or a Script Query — and I’ve run into two related gaps trying to make dashboard filters work dynamically with either.

Problem 1: No supported way to pass a Dashboard Filter value as a query parameter

For a Native SQL (SQL Editor) query, there’s no documented way to receive a dashboard filter’s selected value as a parameter inside the query text. I tried the %(from_date)s style used in Frappe Query Reports — that’s rejected with a ParseError, since it’s not valid syntax for Insights’ query engine. As far as I can tell, there’s currently no equivalent of a “query parameter” that a dashboard filter can feed into a SQL query’s WHERE clause before it runs.

This means the only way a dashboard filter can affect a query at all is the second mechanism below — linking to an output column — which doesn’t work for aggregated queries.

Problem 2: Dashboard filters only link to output columns, not to anything applied before aggregation

When linking a dashboard filter to a chart (“Edit Filter → Linked Charts”), the picker only lists the query’s output columns. For an aggregated query (e.g. grouped by Defect Type with SUM(qty)), there’s no raw Date column left to link to. Adding one back via MIN(date)/MAX(date) doesn’t solve it either — that just filters already-grouped rows after aggregation, giving incorrect totals for the selected period instead of restricting which raw rows get summed in the first place.

I also tried Script Queries, which do have a Variables feature (⋯ → Variables) — I can define e.g. from_date/to_date and use them directly in my Python/frappe.db.sql() code, which works perfectly with fixed test values. But when I create a chart from that Script Query, the dashboard filter’s “Linked Charts” picker still only shows output columns — the Variables aren’t exposed anywhere as something a filter can bind to.

What I’d like to request

Either of these would solve it:

  • Option A: Support binding a dashboard filter directly to a Script Query Variable, so the filter’s value gets passed into the script before it runs (letting the script filter raw rows before aggregating).

  • Option B: Support a proper parameter syntax in the SQL Editor (e.g. something like {{ from_date }}) that a dashboard filter can be linked to and substitute into the query text before execution — similar to how Frappe Query Reports handle %(param)s.

Either way, the core ask is: let a dashboard filter’s value reach a query before it runs (pre-aggregation), not just filter the already-computed result set.

I found at least one other user running into the same wall here: Dashboard Filter for Dynamic SQL query — this seems to affect anyone doing joins + aggregation with a dashboard filter, not just my specific case.

Happy to share a minimal reproducible example if that helps with triage.

Thanks!