How to configure a Filter to view data from previous 'n' days
In some cases, you may want to view data from a specific time range without applying a filter at the data source level. This article provides two solutions to configure a filter at the widget level to view data up to the previous ‘n’ days.
Solution 1: Relative Date Filter
You can utilize the “Link to specific date” option in the relative date filter to filter the data and view the data from the previous ‘n’ days. Let’s say today is June 8, 2023, and you want to view the data from the previous 90 days, say up to March 10, 2023. Choose the “Link to specific date” option and set the date to March 10, 2023. Then, select the period as the past 2 years.
By following the steps above, you will be able to see the data up to March 10, 2023. You can modify the date and period values according to your specific requirements.
Solution 2: Dashboard Parameters
-
Create a dashboard parameter with an integer value, setting the default value to 90.
-
Add the necessary condition with the dashboard parameter in the WHERE query.
-
Run the query, and you will be able to see the data from the previous 90 days.
-
Instead of code view, using expressions and filters, we can achieve this.
Create an expression to subtract days from the date.
IF([Date] < DATESUB(@{{:CountOfDays}}, TODAY()), [Date], NULL)
Filter the null values in the expression in the query filters.
-
Adjust the number of days as needed on the dashboard page to view data from different time ranges.
By using dashboard parameters, you can dynamically change the period of days at the dashboard level and view the data.