Hi,
I have been using text filters so far but now i need field filters but i see that query doesn't work unless some value is passed.
Text filter approach :
where air_line={{ls_airlines}} or *={{ls_airlines}}
In text filter i kept * as default so that query will still work and give result for all airlines.
Field filter approach :
where {{ls_airlines}}
In here, there is no operator used like text filters
Suggest me how may i handle defaults so that i can get results for all airlines without need of passing any value in filter. But then i only need particular airline data once airline is mentioned in field filter.
Hi @hearmyfaith
If you don't set any filter value for a Field Filter, then it will not limit the results.
Have a look here: https://www.metabase.com/learn/sql-questions/field-filters
You probably want to look at Optional Clauses: https://www.metabase.com/docs/latest/questions/native-editor/sql-parameters#optional-clauses
If you are still having problems, then include your entire query and which variable types you're using.
select * from
tables
where
(tables.comp_name={{ls_agency}} or {{ls_agency}}='*')
and (tables.air_line={{ls_airlines}} or '*'={{ls_airlines}})
and (tables.region_name={{ls_region_name}} or '*'={{ls_region_name}})
in above approach i have used * as default value for text filter so it satisfies condition to show all data.
I want all of these to be field filter instead of text filters. On dashboard when i don't select any agency,airline or region then query should show result for all agency,airline and region. Like it should by default show everything from table.
@hearmyfaith Just do this with each variable being a Field Filter
select *
from tables
where true
and {{ls_agency}}
and {{ls_airlines}}
and {{ls_region_name}}