How to Filter Data for the Last 3 Months Excluding This Month

Suppose you have historical data and want to filter data the last 3 months excluding this month. To do so, you can use relative dates filter.

Data Filter with relative dates operator

On a filter dialog, select <relative dates> as Filter Operator, Last N Months (Exclude This Month) as How to Set Value. Then set 3 as Value.

this creates a filter below behind the scene.

between(date, floor_date(today(), unit = "month") %m-% months(3), floor_date(today(), unit = "month") %m-% days(1))

So the filter uses between operator and it uses two edges:

  • Left Edge: The first day of the 3 Months ago
  • Right Edge: The last day of the last month

The first date of the 3 Months ago is calculated as floor_date(today(), unit = "month") %m-% months(3). And the last day of the last month is calculated as floor_date(today(), unit = "month") %m-% days(1)

R Package References

lubridate

For your reference, floor_date() takes a date-time column and rounds it down to the nearest boundary of the specified time unit, in this example month. The floor_date function is from lubridate package.