Date range filter and relative date filter for the same visual

Is there a way to have both a date range filter and a relative date filter for the same visual?

I want to be able to have a visual that shows the last N days that uses a parameter control dropdown with several N values (last 7, 30, 90 days etc.) but then also be able to let a user specify a given date range for the same visual.

Hi @alj_pacho , yes you can have both date range and relative date filter for the same visual and create two controls for it. You have keep in mind that both the filters will act as an AND condition and the visual will be filtered accordingly. Is your requirement to give the end users the flexibility to select one or the other filter?

1 Like

Hi @salim, having the flexibility to select either one would be ideal

Hello @alj_pacho!

My recommendation for this is to follow @salim’s advice above and then for the “last 7, 30, 90 days etc…” control, apply that to the calculated fields.

So you would have your date range parameters applied to a date filter on your target visual, then in your calculated field it would be something like this:

ifelse(
${LookBackWindow} = 'Last 7 Days',
periodOverPeriodDifference(sum(Sales),{Order Date}, DAY, 7),
${LookBackWindow} = 'Last 30 Days',
periodOverPeriodDifference(sum(Sales),{Order Date}, DAY, 30),
etc...,
NULL
)

Quick note, I used the periodOverPeriodDifference function here because I did something similar recently for a table using this function. Depending on how you want to visualize this this may not be the appropriate function.