Date filters

Hello! :slight_smile:
I have a query with two date filters coming from the same table (but from two different columns). It has the structure of the quey below:

image

Can I turn these two filters into one?
I tried as follows:

image

But then I can't enter a period, just a specific date (and that doesn't suit me).

Hi @Helena
Field Filters are connected to a specific field, so you'll either have to make a lookup table or create two separate Date variables.
https://www.metabase.com/learn/sql-questions/sql-variables
https://www.metabase.com/learn/sql-questions/field-filters

1 Like

What do you mean by make a lookup table?

@Helena You would have to create a table or view, which has all the dates, so you can extract min/max.
Have a look here: Using dashboard filters to filter the query without including column in the result

Why should I extract min/max?

@Helena Because you need the min/max, since that is what you need to use for your two columns (date1 between min_date and max_date)

Hi @flamber
I still don't understand... I think I need to create a view. So my data will come out of this format:
image
to this format:
image
And then I will be able to use only one field filter to my date variables. Is that right? Or do I have another option?

@Helena If that works for you, then do that. Otherwise create two Date filters instead (start and end), which you can use more flexible. You cannot control Field Filters in the way you want.

You can create a central table like @flamber suggested in the first post.

For example, create a table called a calendar which will have dates from 01-01-1970 to 01-01-2100 which you can join with the original tables in both of your queries.

In the where clause you can use the filter from the calendar table and use it as a field filter.

Hope this helps

1 Like