Answers / Question 26
SUMIFS / COUNTIFS between two dates leaves out the last day (or returns 0): Excel + Google Sheets fix
Why a SUMIFS or COUNTIFS date range drops everything from the end date when your dates carry times, the one-line fix, tested month and week totals with EOMONTH and EDATE, and the criteria mistakes that make the total 0.
The problem
You total sales, hours or orders between a start date and an end date with SUMIFS (or count them with COUNTIFS), and the result is too low. When you check by hand, everything from the last day of the range is missing: the October report leaves out October 31, the weekly one leaves out Friday. Or the formula returns 0 even though the rows are right there.
Inspired by a public question on Stack Overflow. The problem above is described in our own words and the solution below is ours.
Why it happens
Both apps store a date as a whole number and a time as the fraction after it: Oct 31, 2026 6:45 PM is the 31st plus 0.78 of a day. A date typed into a cell, like your end date 10/31/2026, means midnight at the start of that day. So the condition "<="&F2 only lets in rows up to 12:00 AM on the 31st, and every entry later that day falls outside it.
The sheet often hides this: a column formatted to show only the date can still hold times. Data from forms (Google Forms timestamps), point-of-sale and booking exports, NOW() and Apps Script new Date() nearly always includes them.
=SUMPRODUCT((A2:A500<>"")*(MOD(A2:A500,1)>0))If that formula shows #VALUE!, some "dates" are actually text; see the last section.
The fix: "before the day after" instead of "on or before"
With dates in A, amounts in C, the start date in F1 and the end date in F2, change <= to < and add 1 to the end date. That reads "before midnight at the start of the next day", which covers the whole last day whatever the times are. It gives the same result on plain dates too, so you can use it everywhere.
=SUMIFS(C2:C500,A2:A500,">="&F1,A2:A500,"<"&F2+1)=COUNTIFS(A2:A500,">="&F1,A2:A500,"<"&F2+1)=SUMIFS(C2:C500,A2:A500,">="&F1,A2:A500,"<"&F2+1,B2:B500,"East")=SUM(FILTER(C2:C500,(A2:A500>=F1)*(A2:A500<F2+1)))Keep F1 and F2 as plain dates without a time. If someone types 10/31/2026 5:00 PM into the end cell, the range stops at 5 PM the next day; INT(F2)+1 instead of F2+1 guards against that.
Month, week and "last 7 days" totals
The same pattern, start on or after the first moment and before the first moment of the next period, makes period totals easy and never misses an end-of-day entry:
=SUMIFS(C2:C500,A2:A500,">="&EOMONTH(F3,-1)+1,A2:A500,"<"&EOMONTH(F3,0)+1)=SUMIFS(C$2:C$500,A$2:A$500,">="&E2,A$2:A$500,"<"&EDATE(E2,1))=SUMIFS(C2:C500,A2:A500,">="&TODAY()-6,A2:A500,"<"&TODAY()+1)=SUMIFS(C2:C500,A2:A500,">="&DATE(2026,10,1),A2:A500,"<"&DATE(2026,11,1))Typed dates inside the quotes, like ">=10/1/2026", depend on the file's locale and break when someone in another country opens the file. DATE(year,month,day) works everywhere.
Total is 0? Check the criteria and the dates
- The cell reference is inside the quotes.
">=F1"compares against the text F1 and matches nothing. The operator goes in quotes and the cell joins with&:">="&F1. - The dates are text. Dates pasted from another system can be text that only looks like a date.
=ISNUMBER(A2)shows FALSE for those, and SUMIFS skips them silently. Fix them first with our answer on dates stored as text. - The amounts are text. Then the dates are fine but nothing gets added; see SUMIFS returns 0: numbers stored as text.
- Start and end are swapped, or the ranges have different sizes (A2:A500 with C2:C499 returns an error, not a total).
Good to know
- Google Sheets QUERY has the same trap:
where A <= date '2026-10-31'stops at midnight. Usewhere A < date '2026-11-01'. - AVERAGEIFS, MAXIFS and MINIFS take the same kind of date criteria, so the same
"<"&F2+1fix applies to them. - If you'd rather remove the times for good, a helper column with
=INT(A2)(formatted as a date) gives the plain date. Keep the original column if anyone needs the time. - Times are stored in the spreadsheet's time zone (Google Sheets: File → Settings). Entries made just after midnight in another zone can land on the next day.
- References: Microsoft's SUMIFS function and Google's SUMIFS help pages.
Formulas follow documented Google Sheets / Excel behavior; they aren't machine-tested, so try them on a copy first. Always try new automations on a copy of your sheet first.