Last N days from a selected date

Hi, I have a table wit day, week, and month granularity, and I want to create a control like this to let user select a date and how many days/weeks/months value they want to see. The idea is to let the Last N day control change days/weeks/months value at the same time, so when N = 8, users should be able to see 8 days/ 8 weeks/ 8 months value.
Screen Shot 2022-11-23 at 3.11.31 PM

My current setting for the filter is like this:

time rank is a number column which ranked the date in descending order, snapshot_day is just calendar day. This filter works fine for days but the order of weeks and months are weird.

I wonder if there’s a better way to set up the filters so the orders for different granularity will be right

Hi @Danli_Hu, Are you using the time rank column to sort your day,week and month? From the screenshot it looks like it is sorted in the ascending order(including the day column)? Are you finding it difficult to sort it in descending order? More details on this will help.


1 Like

Hi @Karthik_Tharmarajan, I need the date to sort in ascending order, but the date being displayed have missing some columns, for example, week granularity should displaying week 17,16,15,14… - instead of jumping from 15 to 2

What is your calculated field?

If you find it difficult to get the correct data using Top N filter, consider creating a calculated column using dateDiff function and using a filter on the calculated column. (It is difficult to say why weekly and monthly data is not ordered correctly and has gaps without having more details about how visual is configured, seeing expression for time_rank column and knowing more details about your data)

Hi @Danli_Hu ,

We hope @Tatyana_Yakushev solution worked for you. Let us know if this is resolved. And if it is, please help the community by marking his answer as a “Solution.