Dashboard with filter that controls a SQL text variable

Hey all!

I've created a SQL question that has a text variable. This variable is used in a where condition of the question, and is JSON that we parse and provide to a user-defined function in the query.

It looks like this:

  dbt_production.filter_custom_field_entries({{filter_json}}, to_json_string(custom_field_entries));

Where filter_custom_field_entries is the UDF.

The intention was to use the custom SQL question as a filter table, so I could build dashboards join normal tables (e.g. insights__incidents) onto the filter table, applying the appropriate filters via the text variable, and use the result in dashboard graphs.

But I'd hit a problem: I can't create a dashboard filter that can be used in the custom SQL question.

Is there no way to have a dashboard parameterise a custom SQL question with filters?

Totally stuck here, so thanks for any help!

Hi @lawrencejones
Either I'm misunderstand what you're doing or you're just not selecting a filter.
You cannot pass-thru filters to nested questions, if that is what you're asking:
https://github.com/metabase/metabase/issues/6449 - upvote by clicking :+1: on the first post
If you are just trying to use the SQL query you're showing with a Text variable, then you can add that directly to a dashboard and connect a Text Dropdown filter.

Thank you for replying so fast.

You're right and my question was missing some key context: I can provide filter_json as a dashboard filter if the question is used wholesale, as in the question is loaded as a dashboard panel and nothing else is done to it.

But if I want to use the custom SQL question with the dashboard filter as a join in a separate question, I can no longer link the dashboard filter to the filter_json of the custom SQL question.

I'm linking a screenshot showing how the original data "Insights Incidents" is meant to be joined onto "Incident filter table", and the resulting question (Incidents by size and severity) is no longer able to be linked to the dashboard filter.

I'm getting the vibe this might not be possible :confused:

@lawrencejones That's issue 6449. You'll have to do everything in SQL.

Thanks for the help, fingers crossed 6449 eventually lands.