Sub topic 12
Filtering by date and date ranges
This chapter assumes you can write a basic SUMIFS or COUNTIFS formula, that you know how criteria pairs work, and that you can join an operator to a cell value with &. It uses the sales layout from earlier chapters: dates in column A, regions in B, products in C, amounts in D, and rows 2 to 100.
How Excel stores dates
Excel stores a date as a serial number, which counts days from a starting point. January 1, 2025 is 45658. The cell only displays it as a date because of its number format.
The *IFS functions compare these numbers. A date criterion is therefore a numeric comparison, and the operators from the previous chapter work on dates without change.
Build date criteria with DATE
Write a date inside a criterion with the DATE function, not as typed text. DATE takes year, month and day, and it returns the same serial number in every regional setting.
=SUMIFS(D2:D100, A2:A100, ">=" & DATE(2025,1,1))The & joins the text ">=" to the number 45658, so Excel receives the criterion ">=45658". This formula adds every amount dated January 1, 2025 or later.
Typing ">=1/1/2025" as text sometimes works. Excel has to convert that text using your computer's regional settings, so the same workbook can give different results on another machine. A date like "3/4/2025" can mean March 4 or April 3.
Use two pairs for a range
A date range needs a start and an end. Use the date column twice, once for each end:
=SUMIFS(D2:D100, A2:A100, ">=" & DATE(2025,1,1), A2:A100, "<" & DATE(2025,2,1))The conditions are combined with AND, so a row counts only if the date is on or after January 1 and before February 1. With the sample data, this returns 1500, which is 1200 for the laptop on January 5 plus 300 for the monitor on January 9.
Why the end date is exclusive
The formula ends with "<" and the first day of the next month. It does not end with "<=" and January 31. There are two reasons:
- If a date cell holds a time, such as 2025-01-31 14:30, its serial number is 45688.604. That is greater than 45688, so
"<=" & DATE(2025,1,31)skips it. - You do not need to know whether a month has 28, 30 or 31 days. The next month always starts on day 1.
=COUNTIFS(A2:A100, ">=" & DATE(2025,1,1), A2:A100, "<" & DATE(2025,2,1))This counts the rows in January 2025.
Drive the range from cells
Hard-coded dates are hard to reuse. Put the start in G1 and the end in G2 and refer to them:
=SUMIFS(D2:D100, A2:A100, ">=" & G1, A2:A100, "<" & G2 + 1)Adding 1 to G2 means a person can type the last day they want, such as January 31, and the formula still treats it as included. If G2 might hold a date with a time, use INT(G2) + 1.
For a whole month, you can give one cell, such as the first day of the month in G1, and calculate the end with EDATE:
=SUMIFS(D2:D100, A2:A100, ">=" & G1, A2:A100, "<" & EDATE(G1, 1))EDATE moves a date forward by a number of months. Because it handles different month lengths for you, this pattern is safe for every month in the year.
Common date patterns
| Goal | Criteria pairs on the date column |
|---|---|
| On one day | `A2:A100, DATE(2025,1,5)` |
| From a date onward | `A2:A100, ">=" & DATE(2025,1,1)` |
| Before a date | `A2:A100, "<" & DATE(2025,1,1)` |
| A whole month | `">=" & G1` and `"<" & EDATE(G1,1)` |
| A whole year | `">=" & DATE(2025,1,1)` and `"<" & DATE(2026,1,1)` |
| Last 30 days, including today | `">=" & TODAY()-29` and `"<" & TODAY()+1` |
An exact-day match, as in the first row, works only when the cells contain no time. If they might, use a range from that day to the next day.
You cannot wrap the range in a function such as YEAR(A2:A100)=2025 inside SUMIFS. The criteria range must be a real range, not a calculated array. A start and end pair does the same job.
Combine dates with other conditions
Date pairs sit alongside any other pairs. This totals West sales in February 2025:
=SUMIFS(D2:D100, B2:B100, "West", A2:A100, ">=" & DATE(2025,2,1), A2:A100, "<" & DATE(2025,3,1))With the sample data the result is 310, from the West monitor on February 2. The North laptop on February 14 is excluded by the region condition.
Decide how to write the criteria
Troubleshooting date criteria
When a date formula returns 0 or a total that looks too small, check these causes in order.
- The dates are text. Select a date cell and look at its alignment. Dates are usually right-aligned and text is left-aligned. Test with
=ISNUMBER(A2). If it returns FALSE, the *IFS functions cannot compare it. Convert the column with Data > Text to Columns, or multiply by 1 in a helper column. - Times are hiding in the cells. Use an exclusive end date, as shown above.
- The operator is not joined with
&. Writing">=DATE(2025,1,1)"inside the quotes passes the characters DATE as text, so nothing matches. - The ranges differ in size. Each criteria range must have exactly as many rows as the sum range. Otherwise the result is
#VALUE!. - The cell holding the date is empty.
">=" & G1with an empty G1 becomes">=", and the result is unreliable. Check that the input cells are filled.
=COUNTIFS(A2:A100, ">=" & DATE(2025,1,1), A2:A100, "<" & DATE(2025,2,1)) - SUMPRODUCT(--ISNUMBER(A2:A100))This formula is not meant for production. It is a quick diagnostic. Compare =COUNTA(A2:A100) with =SUMPRODUCT(--ISNUMBER(A2:A100)). If the first is larger, some entries are not real dates.
Averaging over a period
AVERAGEIFS takes the same date pairs. If no row falls in the period, it returns #DIV/0!, which a later chapter handles with IFERROR.
=AVERAGEIFS(D2:D100, A2:A100, ">=" & DATE(2025,2,1), A2:A100, "<" & DATE(2025,3,1))With the sample data this gives 730, the mean of 310 and 1150.
Exercise
Using the sample data, write a formula that counts West rows dated in January 2025. What does it return?
Show answer
=COUNTIFS(B2:B100, "West", A2:A100, ">=" & DATE(2025,1,1), A2:A100, "<" & DATE(2025,2,1)). It returns 1, the laptop sale on 2025-01-05. The monitor on 2025-01-09 is in January but belongs to East.
Exercise
A report uses "<=" & DATE(2025,1,31) as the end of January and misses some rows. What is the likely cause, and how do you fix it?
Show answer
Some date cells contain a time, so a value such as 2025-01-31 14:30 is larger than the serial number for January 31. Change the end condition to "<" & DATE(2025,2,1).