Sub topic 12
Filtering by date and date ranges
This chapter assumes you can write a basic SUMIFS formula and use comparison operators in criteria. It also assumes you know how to join an operator to a cell value with &. Here you apply those ideas to dates.
Dates are numbers
Excel stores a date as a serial number, the count of days since 1 January 1900. The date 2025-01-05 is stored as 45662. Because dates are numbers, the comparison operators >=, <, and <> work on them in the same way they work on amounts.
The sample data keeps its dates in column A, with amounts in column D.
A: Date B: Region C: Product D: Amount E: Notes
2025-01-05 West Laptop 1200
2025-01-09 East Monitor 300 Backorder
2025-02-02 West Monitor 310
2025-02-14 North Laptop 1150 GiftBuild a date range with two criteria
To select a range of dates, use the date column in two criteria pairs. One pair sets the start and the other sets the end. This formula totals all of January 2025.
=SUMIFS(D2:D100, A2:A100, ">=" & DATE(2025,1,1), A2:A100, "<" & DATE(2025,2,1))The two conditions are combined with AND. A row must be on or after 1 January and before 1 February to be included.
The end date is exclusive. Using "<" & DATE(2025,2,1) includes every moment of 31 January, even if a cell holds a time of day. Using "<=" & DATE(2025,1,31) would drop any value on 31 January that has a time after midnight.
Why you need DATE and the `&`
Writing the criteria as ">=2025-01-01" often fails or behaves differently depending on regional settings. Excel may read the text in an unexpected way. DATE(year, month, day) returns the serial number directly, so the result does not depend on how your computer formats dates.
The & is required because the operator and the value must become one text string. ">=" & DATE(2025,1,1) becomes ">=45658".
Take dates from cells
You can keep the start and end dates in cells and refer to them. If G1 holds the start date and G2 holds the end date, use this formula.
=SUMIFS(D2:D100, A2:A100, ">=" & G1, A2:A100, "<" & G2)Changing G1 or G2 updates the total with no edit to the formula. The cells must contain real dates, not text that only looks like dates.
Common date problems
- Total is 0 but matching rows exist. The dates in column A are probably text. A real date is right-aligned by default, and text is left-aligned. Convert the text to dates and try again.
- The last day is missing. The end criterion probably uses
<=with a date-only value while the cells contain times. Switch to<with the following day. - The wrong month is included. Check that the end date is the first day of the next month, not the last day of the current one.
Exercise
Write a COUNTIFS formula that counts the rows in A2:A100 dated in February 2025.
Show answer
=COUNTIFS(A2:A100, ">=" & DATE(2025,2,1), A2:A100, "<" & DATE(2025,3,1))
Exercise
Why is the end of a date range better written as "<" with the next day than as "<=" with the last day?
Show answer
Cells that contain a time of day, such as 2025-01-31 14:00, are greater than the date 2025-01-31 at midnight. A "<=" test would leave them out. A "<" test against the next day includes them.