A sql question with a date range filter

How do I create a sql question that I can apply a date range filter to on the dashboard? The variables panel doesn’t have a way to select a date range as a type for completion.

for example, if I had sql like below, I’d expect to be able to choose a “DATE RANGE” from the variables panel or something like that.
SELECT
foo.name
foo.start
FROM
foo
WHERE
foo BETWEEN {{range}}

Hi! You have to select type “Field Filter” and then choose the applicable date field you want to use for filtering. Your custom SQL should look something like this:
SELECT
foo.name
foo.start
FROM
foo
WHERE {{date}}

Then in the dashboard you just add a date range filter normally and select the date field you added as a variable for your chart.

2 Likes

That worked!
Thanks for your help.

The field filter is not working - the dashboard is reporting an error in the widget.

This is my query: please advice

SELECT COUNT(DISTINCT Question Sessions.id) AS Count of distinct Question Sessions Id
FROM question_sessions AS Question Sessions
WHERE {{date}} AND Question Sessions.is_mobile = TRUE
AND ((Question Sessions.campaign_id = {{ID}})
LIMIT 1000;

If found the problem - it has sth to do with using the table alias - the alias is automatically inserted by the metabase editor - when I removed the table alias and replaced it with the table name it solved the issue.

1 Like

Thanks a lot. It was 2 hours with the same problem. :slight_smile: