HogQL insight works with Dashboard filters
Is your feature request related to a problem?
If I add a filter to a dashboard, or change the timeline, I want my HogQL insight to be filtered by that filter too.
Describe the solution you'd like
HogQL queries get filtered down. Either more explicitly by defining it:
SELECT * FROM events WHERE {event_filters}
or maybe just automagically?
Describe alternatives you've considered
Additional context
Thank you for your feature request – we love each and every one!
The first step towards this was done here: https://github.com/PostHog/posthog/pull/15973
Regarding automagically, I'd love this to work, but our internal discussion concluded that this may be too tricky. E.g. subqueries to answer questions like "was this the first time the user performed $event" might have a longer time range than the "last 30 days" range the answers are calculated for.
Thus we'll at least need an opt out, such as SETTINGS ignore_dashboard_filteres=true at the end of the HogQL query.
However my vote goes for:
- Add the same row of filters (24h timerange + property filter) that are on dashboards into the SQL insight editing view.
- Add
AND {event_filters}as part of the default query when you open the SQL insight tab. This would teach people about this feature, and how to make their custom insights "dashboard compatible". - Update the
HogQLQuerynode to take an optional{ event_filters: { properties, date_from, date_to } }parameter
Potential related Issues / PRs:
- feat(hogql): add to dashboard filters: This pull request addresses a similar issue where users wanted to filter by SQL on the dashboard. The changes made in this pull request add the missing HogQL filter, which allows users to filter the results of the graphs. This could be helpful in understanding how to implement the desired feature of filtering HogQL insights based on dashboard filters.
This message was generated by AI from www.triagetickets.com
for HogQL Table, I have already input it into the dashboard, but I cannot use the filters General available in the dashboard. Even though I have written the query as WHERE {filters}.
HI @putriapriandi, that doesn't sound right! Can you link to the insight here, so that we can investigate? (No worries, only us at PostHog will be able to do anything with this link)
Closing as I believe all insights should now work (let us know if that's not the case!)
Trying to query hog-managed mysql db.
{filters} -> Cannot use 'filters' placeholder in a SELECT clause that does not select from the events or sessions table.
{event_filters} -> Unable to resolve field: event_filters
{date_from} -> Unable to resolve field: date_from
{date_to} -> Unable to resolve field: date_to
same issue here! @abrambailey did you find any solution?
No, unfortunately. Ended up moving to self hosted metabase.