Sub topic 9
Filtering by date and date ranges
This chapter covers how SUMIFS, COUNTIFS, and AVERAGEIFS compare dates, and how to write a start and end boundary that stays correct when cells hold times. It assumes you can already write a two-criteria formula, use comparison operators such as ">=", and join an operator to a cell value with &.
How Sheets stores dates
A date in Google Sheets is a number. It counts the days since December 30, 1899, so January 1, 2026 is stored as 46023. A time of day is the fractional part, so noon on that day is 46023.5. A formatted cell only changes how that number looks.
The criteria functions compare these numbers. Every date filter therefore follows one rule: build a criterion whose operator and number are what you intend.
The examples use this layout, with data in rows 2 to 100:
| Column | Header | Contents |
|---|---|---|
| A | Region | Text such as West or East |
| B | Product | Text |
| C | Order Date | Real dates, possibly with times |
| D | Units | Numbers |
| E | Revenue | Numbers |
Matching one date
For an exact day, you can pass a date cell or a DATE result directly:
=COUNTIFS(C2:C100, DATE(2026,1,15))This counts rows whose value equals 46037, which is January 15, 2026 at midnight. It works only if the cells are pure dates. A cell holding 2026-01-15 09:30 is 46037.39..., which is not equal, so the row is skipped. For anything that might carry a time, use a range, described below.
Building a range with two criteria on one column
A date range uses the same column twice: once for the start and once for the end. Both pairs must be true, which is the AND logic from earlier chapters.
=COUNTIFS(A2:A100, "West", C2:C100, ">="&DATE(2026,1,1), C2:C100, "<"&DATE(2026,2,1))Here the operator is text and DATE(...) is a number. The & joins them into a single string such as ">=46023", which the function then parses. If you leave out the & and write ">=" DATE(2026,1,1), Sheets reports a formula parse error.
Use an exclusive end
The example ends with "<"&DATE(2026,2,1), not "<="&DATE(2026,1,31). The reason is time of day. The value 2026-01-31 14:00 is larger than the serial number for January 31 at midnight, so <= January 31 drops every order placed after midnight on the last day. Using "less than the first day of the next month" includes the whole of January whether or not cells hold times.
Driving the range from cells
Hard-coded dates are hard to maintain. Put the start and end in cells and join them to the operators. Suppose G1 holds the start date and G2 holds the last day you want included:
=SUMIFS(E2:E100, C2:C100, ">="&G1, C2:C100, "<"&(G2+1))Adding 1 to the last day gives the exclusive end, so people type the natural end date and the formula still includes all of it. The parentheses matter for readability. The + is evaluated before & in any case, but the brackets show the intent.
If G1 contains text that only looks like a date, the join still produces a number-like string, but no rows match. See the gotchas section.
Dates relative to today
TODAY() returns today's date without a time, so it works in the same pattern:
=COUNTIFS(C2:C100, ">="&(TODAY()-30), C2:C100, "<"&(TODAY()+1))This counts rows from the last 30 days plus today. The result changes each day because TODAY() recalculates, so use a fixed date cell when you need a reproducible report.
Whole months from a single cell
If G1 holds any date in the month you want, you can derive both edges with EOMONTH. EOMONTH(G1, -1)+1 is the first day of G1's month. EOMONTH(G1, 0)+1 is the first day of the following month.
=SUMIFS(E2:E100,
C2:C100, ">"&EOMONTH(G1,-1),
C2:C100, "<="&EOMONTH(G1,0))This version uses > the last day of the previous month, so it avoids a +1. It has the same time-of-day problem as <= above, because EOMONTH(G1,0) is midnight at the start of the last day. The safer form is:
=SUMIFS(E2:E100,
C2:C100, ">="&(EOMONTH(G1,-1)+1),
C2:C100, "<"&(EOMONTH(G1,0)+1))Line breaks inside a formula are allowed in Sheets (press Ctrl+Enter or Cmd+Enter while editing) and make long criteria lists easier to read.
Common date errors
Most failures come from one of these causes.
- Dates stored as text. If a column was pasted or imported as text, the cells are left-aligned and
ISNUMBER(C2)returns FALSE. Numeric comparison then matches nothing. Convert the column withDATEVALUEin a helper column, or re-enter the data with a date format applied. - Missing quotes around the operator. The operator must be a string, as in
">="&G1. Writing>=&G1is a syntax error. - Using
<=with a date that has times. Described earlier. Prefer the exclusive end. - Locale-dependent literals. A string such as
">=1/2/2026"is read according to the spreadsheet's locale, so it may mean January 2 or February 1.DATE(2026,2,1)has no such ambiguity, so use it. - Mismatched range sizes. The date range
C2:C100must have the same number of rows as every other range in the formula, or Sheets returns#VALUE!. - Blank date cells. A blank cell is not matched by
">="&DATE(...), so blanks drop out silently. If a missing date should count as a problem, check with a separateCOUNTIFS(C2:C100, "").
Filtering by month or year across years
The criteria functions compare whole values, so they cannot ask for "any January in any year". For that you have two options. You can add a helper column with =MONTH(C2) and use it as a normal numeric criterion. Or you can use SUMPRODUCT, as in =SUMPRODUCT((MONTH(C2:C100)=1)*E2:E100). The helper column is usually easier to audit and faster on large sheets.
Quick reference
| Goal | Criteria pair |
|---|---|
| On or after a date | `C2:C100, ">="&G1` |
| Before a date | `C2:C100, "<"&G1` |
| Exactly one day (pure dates) | `C2:C100, G1` |
| One whole day (times possible) | `">="&G1` and `"<"&(G1+1)` |
| Whole month of G1 | `">="&(EOMONTH(G1,-1)+1)` and `"<"&(EOMONTH(G1,0)+1)` |
| Last 7 days including today | `">="&(TODAY()-6)` and `"<"&(TODAY()+1)` |
Averages over a period
AVERAGEIFS takes the same pairs. The average range comes first, and an empty period returns #DIV/0!, so wrap it as you learned earlier:
=IFERROR(AVERAGEIFS(E2:E100, A2:A100, "West", C2:C100, ">="&G1, C2:C100, "<"&(G2+1)), "No matches")Exercise
Column C holds order dates and times. G1 holds 2026-03-01 and G2 holds 2026-03-31, the last day to include. Write a formula that sums Revenue (E2:E100) for the West region (A2:A100) for all of March, including orders placed late on March 31. Why not use "<="&G2?
Show answer
=SUMIFS(E2:E100, A2:A100, "West", C2:C100, ">="&G1, C2:C100, "<"&(G2+1)). The value of "<="&G2 compares against March 31 at 00:00, so an order at 14:00 on March 31 has a larger serial number and is excluded. Using "<" with G2+1 sets the end at April 1 at 00:00, which includes the whole of March 31 and nothing from April.
Exercise
A COUNTIFS date filter returns 0, but you can see rows in the date range. The date cells are left-aligned. What is the likely cause and how do you check it?
Show answer
The cells are probably text, not real dates, so numeric comparison never matches. Check with =ISNUMBER(C2), which returns FALSE for text. Fix it by converting with DATEVALUE in a helper column, or by re-entering the values with a date format applied.