Hi Insights team,
I’m trying to build a dashboard where a Date range filter (added via “Add Filter” on the dashboard) drives the data behind several charts. My underlying data needs joins across multiple tables and aggregation (grouping, sums, top-N with an “Other” bucket), so a plain single-table Query Builder chart doesn’t cover my case — I need either SQL or a Script Query.
What I ran into:
-
SQL Editor (Native SQL) queries — I can’t find any supported way to pass a runtime parameter from a dashboard filter into the
WHEREclause of a hand-written SQL query. The old-style%(from_date)ssyntax (used in Frappe Query Reports) isn’t accepted and returns a ParseError. -
Dashboard filter → column linking — When editing a dashboard filter and linking it to a chart, the “Linked Charts” picker only lists the query’s output columns. If my query is aggregated (e.g. grouped by Defect Type with
SUM(qty)), there’s no rawDatecolumn left to link the filter to — and even if I add one back usingMIN(date)/MAX(date), the filter would only apply after aggregation (filtering already-grouped rows), which gives incorrect totals for the selected period instead of restricting which rows get summed. -
Script Query “Variables” — I found that Script Queries support a Variables feature (via ⋯ → Variables), which lets me define named variables (e.g.
from_date,to_date) and reference them directly in my Python code. This works great when I set fixed values manually while building the query. However, when I create a chart from this Script Query and try to link it to a dashboard filter, the “Linked Charts” column picker still only shows the query’s output columns — the Variables I defined don’t appear anywhere as something a dashboard filter can bind to.
What I’d like to request:
Please add support for linking a dashboard filter directly to a Script Query’s Variable (not just to output columns). This would let the filter’s selected value get passed into the script before it runs — so the script can use it inside frappe.db.sql(...) (or similar) to filter raw rows before aggregation, which is the only way to get period-correct totals for a grouped/aggregated report.
This seems like a natural extension of the Variables feature that already exists — it just needs to be exposed as a bindable target in the dashboard filter’s “Linked Charts” UI, the same way output columns already are.
I also noticed at least one other user asking about a closely related problem here: Dashboard Filter for Dynamic SQL query — so this seems to be a genuine gap for anyone using SQL/Script queries with joins + aggregation, not just simple single-table charts.
Happy to share my exact use case/query in more detail if that’s useful for reproducing this.
Thanks!