Dynamically add plots on the basis of field filter values

Hi everyone,

Here's my issue: I'm trying to create a dynamic dashboard that display the seperate plots for each value selected in the dashboard's field filter widget.
For example, let's say we have 5 values coming up in the dropdown list of widget and when user selects one or multiple values then correspondingly for some table 'T' in SQL Server linked to the metabase we get the records with that particular value in a column 'C' of the latter table.

Let's say values in the widget are a, b, c and d. So, when user selects the 'a' then the all records with value 'a' in a particular column gets selected and the plot is populated.

When user selects the multiple values in the widget like 'a', 'b' and 'd' then for each of these values seperate question with respective plot should get created.

Kindly help me out.

Thanks!

Hi @Ahriman01
You would have to do some elaborate hacking of Field Filters to be able to do something dynamically.
It's just using Complex Default Value, when combined with Optional Clauses:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#default-value-in-the-query

I cannot vouch if this would continue to work in future versions. Example on H2 Sample Dataset:

SELECT parsedatetime(year("CREATED_AT"), 'yyyy') AS "CREATED_AT",
[["CATEGORY" AS "CATEGORY", count(*) AS "count" FROM "PRODUCTS" WHERE {{category_field_filter}} GROUP BY parsedatetime(year("CREATED_AT"), 'yyyy'), "CATEGORY" --]] count(*) AS "count" FROM "PRODUCTS" GROUP BY parsedatetime(year("CREATED_AT"), 'yyyy')
ORDER BY parsedatetime(year("CREATED_AT"), 'yyyy') ASC

You probably want to upvote the following issue, since that would be safer if that was implemented:
https://github.com/metabase/metabase/issues/6820 - upvote by clicking :+1: on the first post

Hi @flamber
Thanks for replying but my issue is that I want the new plots/questions should generate for each value we select in the dashboard's field filter widget.

For example, let's say initially we don't have any value selected in the widget so we'll get the default one only and when user selects value 'a' in the dashboard widget then new plot should get added in the dashboard whose query will be:
SELECT * FROM <TABLE_NAME> WHERE <COLUMN_NAME> = <ANY_VALUE> AND {{a}}

Similarly if user selects another value in the widget let's say 'b' then new plot with question as SELECT * FROM <TABLE_NAME> WHERE <COLUMN_NAME> = <ANY_VALUE> AND {{b}} should get populated right below the previous one and when user removes any value from the selected ones in the widget then respective plots/questions should get removed.

Kindly help me in achieving this functionality.

Thanks!!

@Ahriman01 That is exactly what the query example I have given does. Try it out on Sample Dataset.