Field filter can be attached only to exist model. But if I make SQL query why I can’t use result fields as source for date filter?
Particularly I have a table that I need to filter by one of two date fields
created between {range} OR updated between {range}
Of course, I can make it with two simple date filters
created between {{start_date}} AND {{end_date}} OR updated between {{start_date}} AND {{end_date}}
but this way I can’t use day/month/year or ‘previous’ filters.
But if the filter had another setting for the source expression, I could use, for example
IFNULL(table.updated,table.created)
OR
I could add this expression to the select list and use it by alias in the filter
Hi @Crusader
It’s currently not possible to use Field Filters in that way. If you have a “fake” table containing dates (like MariaDB’s sequence
), then you could use that table as a sub-query for your between
statements.
I think you’re looking for this request:
https://github.com/metabase/metabase/issues/5082
So how to make created BETWEEN {{date1}} AND {{date2}} OR updated BETWEEN {{date1}} AND {{date2}}
with ‘fake table’ workaround?
Best way is to make field to filter binding, something like {{created=filter1}} OR {{updated=filter1}}
then if I select in filter1 BETWEEN date1 AND date2
this filter apllies to both fields.
For now filters with OR is useless
@Crusader
Which database are you querying?
If you make a sub-query, then you can use Field Filters, and from the sub-query you would extract the MIN()
and MAX()
dates, which could be used for the created
and updated
columns.
EDIT: You might want to upvote this issue by clicking on the first post:
https://github.com/metabase/metabase/issues/6947