Filter dashboard by default on last 7 days

How can I filter dashboard on last 7 days by default but also give the date option.

Hi @Anum
Use the "Default filter value":
https://www.metabase.com/docs/latest/users-guide/08-dashboard-filters.html

I want to create a filter on single date from start date to end date and which filters by default on last 7 days, i.e., last seven days to current date when the date is not provided.

@flamber can we fix this syntax for mysql?https://github.com/metabase/metabase/issues/3156#issuecomment-330791787

Something along the lines
where created_at>{{default last 7 days}} and created_at<= {{default today}}

Here, last 7 days is a starting time and default today is the ending time. I want it to filter it by default on last 7 days but if it should also work on the given date.

@Anum Post "Diagnostic Info" from Admin > Troubleshooting.

Failed query log?

@Anum

{
"browser-info": {
"language": "en-US",
"platform": "Win32",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36",
"vendor": "Google Inc."
},
"system-info": {
"file.encoding": "UTF-8",
"java.runtime.name": "OpenJDK Runtime Environment",
"java.runtime.version": "11.0.10+9-LTS",
"java.vendor": "Amazon.com Inc.",
"java.vendor.url": "https://aws.amazon.com/corretto/",
"java.version": "11.0.10",
"java.vm.name": "OpenJDK 64-Bit Server VM",
"java.vm.version": "11.0.10+9-LTS",
"os.name": "Linux",
"os.version": "4.14.225-169.362.amzn2.x86_64",
"user.language": "en",
"user.timezone": "UTC"
},
"metabase-info": {
"databases": [
"h2",
"mysql"
],
"hosting-env": "unknown",
"application-database": "mysql",
"application-database-details": {
"database": {
"name": "MySQL",
"version": "5.7.34-log"
},
"jdbc-driver": {
"name": "MariaDB Connector/J",
"version": "2.6.2"
}
},
"run-mode": "prod",
"version": {
"date": "2020-12-03",
"tag": "v0.37.3",
"branch": "release-x.37.x",
"hash": "2f1e783"
},
"settings": {
"report-timezone": null
}
}
}

@flamber

# Total orders
Select count(*) as TotalOrders
From order 
where [[and created_at>={{start_date}} and created_at<={{end_date}}]]

@flamber
If date is not provided it should find from current to last seven days, i.e., start_date = 21April,2021 and end_date=28April,2021

@Anum Then you can use Complex Default Values in the Optional Clauses:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#setting-a-default-value

Select count(*) as TotalOrders
From order 
where 1=1
[[and created_at>={{start_date}} and created_at<={{end_date}} #]] and created_at>=(DATE(NOW()) + INTERVAL -6 DAY) and created_at<=DATE(NOW())
2 Likes

Thank you @flamber. You are truly amazing.