Field filter with If statement

Hey,

I’ve read https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#the-field-filter-variable-type

However didn’t find any solution…

I’d like MySQL to return true if field filter contains 1988, or return false if it doesn’t :

if (find_in_set(1988, {{variable}}) <> 0, "true", "false")

However field filter only returns 0 or 1 as as a value even if the value set in the input is another number.

Any idea ?

A bit similar to this question : Field Filter for Query does not return result, but Text Field works

But it’s for MongoDB and I’m looking answers in MySQL.

Hi @Alexandre
Field Filters are different from the other filters, since it inserts SQL including the column reference: https://www.metabase.com/blog/field-filters/index.html
You would have to do something like this:
if (find_in_set(1988, (SELECT column FROM table WHERE {{variable}})) <> 0, "true", "false")
Or just use Number filter instead: https://www.metabase.com/blog/sql-template-variables/index.html

Thanks @flamber.

However it works only for a single value. I tried to use GROUP_CONCAT or CONCAT with field filters. Example :

group_concat((select column FROM table WHERE {{variable}}) separator ', ')

But it doesn’t work. => Subquery returns more than 1 row. However I don’t get why it doesn’t concatenate the multiple rows.

Any idea on how to do that when field filter has multiple values ?

@Alexandre I don’t know your structure, and that query don’t look correct.