posthog icon indicating copy to clipboard operation
posthog copied to clipboard

HogQL insight works with Dashboard filters

Open timgl opened this issue 2 years ago • 3 comments

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!

timgl avatar Jun 12 '23 13:06 timgl

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:

  1. Add the same row of filters (24h timerange + property filter) that are on dashboards into the SQL insight editing view.
  2. 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".
  3. Update the HogQLQuery node to take an optional { event_filters: { properties, date_from, date_to } } parameter

mariusandra avatar Jun 12 '23 14:06 mariusandra

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

ithinkwong avatar Jun 26 '23 03:06 ithinkwong

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}.

putriapriandi avatar May 22 '24 06:05 putriapriandi

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)

Twixes avatar Jun 19 '24 12:06 Twixes

Closing as I believe all insights should now work (let us know if that's not the case!)

Twixes avatar Jul 09 '24 12:07 Twixes

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

abrambailey avatar Oct 23 '24 08:10 abrambailey

same issue here! @abrambailey did you find any solution?

joumanam avatar Apr 23 '25 10:04 joumanam

No, unfortunately. Ended up moving to self hosted metabase.

abrambailey avatar Apr 23 '25 11:04 abrambailey