To sum values in Google Sheets based on a date condition, use the SUMIF function with a date criterion like "=2024-01-15" or a date range like ">=2024-01-01". The basic syntax is =SUMIF(range, criterion, [sum_range]), where range is the column of dates to check, criterion is the condition (often a date or cell reference), and sum_range is the column of values to add. For example, =SUMIF(A2:A100, ">=2024-01-01", B2:B100) sums all amounts in B2:B100 where the date in A2:A100 is on or after January 1, 2024.
Understanding SUMIF with Dates
SUMIF is a standard Google Sheets function that adds numbers in a range based on a single condition. When the condition involves dates, the key is to write the criterion so Sheets recognizes it as a date, not as text. Dates in Google Sheets are stored as serial numbers (the number of days since December 30, 1899), but you can type them in a human-readable format within the formula. The function compares the serial numbers, so any valid date format works.
For example, if you have a list of sales with dates in column A and amounts in column B, to sum sales that happened exactly on March 15, 2024, you would use:
=SUMIF(A2:A100, "2024-03-15", B2:B100)
This works because the criterion is a text string that Sheets parses as a date. If you prefer, you can reference a cell containing a date instead: =SUMIF(A2:A100, C1, B2:B100) where C1 holds the date.
How to Use Date Comparisons in SUMIF
To sum values where the date is before, after, or between specific dates, you use comparison operators inside the criterion. The operators are > (greater than), < (less than), >=, <=, and <> (not equal to). The criterion must be a text string that includes the operator and the date, enclosed in double quotes. For example:
- After a date:
=SUMIF(A2:A100, ">2024-01-01", B2:B100)sums amounts where the date is after January 1, 2024. - On or before a date:
=SUMIF(A2:A100, "<=2024-12-31", B2:B100)sums amounts up to and including December 31, 2024. - Not on a specific date:
=SUMIF(A2:A100, "<>2024-06-15", B2:B100)sums all amounts except those on June 15, 2024.
When you need to sum between two dates (e.g., all sales in January 2024), SUMIF alone cannot handle two conditions. You have two options: use SUMIFS (which supports multiple criteria) or subtract two SUMIF results. For instance, to sum between January 1 and January 31, 2024, you could use:
=SUMIFS(B2:B100, A2:A100, ">=2024-01-01", A2:A100, "<=2024-01-31")
Or equivalently: =SUMIF(A2:A100, ">=2024-01-01", B2:B100) - SUMIF(A2:A100, ">2024-01-31", B2:B100). The first method is clearer and less error-prone.
Using Cell References for Dates
Hardcoding dates in formulas works, but it's often better to reference a cell that contains the date. This makes the formula dynamic—if you change the date in the cell, the sum updates. To use a cell reference in the criterion, you concatenate the operator with the cell reference using the ampersand (&). For example, if cell D1 contains the date 2024-01-01, the formula to sum amounts after that date is:
=SUMIF(A2:A100, ">"&D1, B2:B100)
The ampersand joins the text ">" with the date serial number in D1, creating a criterion like ">45292" (the serial number for Jan 1, 2024). Sheets interprets this correctly. If you omit the ampersand and write ">D1", Sheets treats it as text and returns 0 because no date equals the literal string ">D1".
For an exact match, you can reference the cell directly without concatenation: =SUMIF(A2:A100, D1, B2:B100). This works because the criterion is a date value, not a string.
Common Problems and Mistakes
Several pitfalls trip up users when using SUMIF with dates:
- Text-formatted dates: If your date column contains text (e.g., "Jan 1, 2024" as a string), SUMIF won't match it against a real date. Convert text to dates using
DATEVALUEor the Data > Split text to columns feature. - Wrong operator in quotes: Forgetting to enclose the operator and date in quotes, or using a cell reference without the ampersand, causes the criterion to be treated as text.
- Date range not inclusive: When summing a month, remember to use
<=for the last day, or use<the first day of the next month. For example,<2024-02-01is equivalent to<=2024-01-31. - SUMIF vs SUMIFS order: In SUMIF, the range comes first, then the criterion, then the sum range. In SUMIFS, the sum range comes first, then the criteria pairs. Mixing them up returns errors or wrong results.
Another common issue is using the DATE function inside the criterion. For instance, =SUMIF(A2:A100, ">"&DATE(2024,1,1), B2:B100) works because the DATE function returns a serial number, and the ampersand converts it to text. This is a robust way to avoid date format ambiguity.
SUMIF vs SUMIFS vs QUERY
SUMIF is ideal for a single condition. When you need multiple conditions (e.g., date range and a product category), SUMIFS is the better choice. Its syntax is =SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...]). For example, to sum sales of "Widget" (column C) in January 2024:
=SUMIFS(B2:B100, A2:A100, ">=2024-01-01", A2:A100, "<=2024-01-31", C2:C100, "Widget")
For more complex date logic—like summing by month or year without a helper column—the QUERY function is more powerful. QUERY uses a Google Visualization API query language. For example, to sum amounts by month:
=QUERY(A1:B100, "select month(A)+1, sum(B) where A is not null group by month(A) label month(A)+1 'Month'")
This returns a two-column table of month numbers and sums. QUERY is also handy for summing dates in the current year: =QUERY(A1:B100, "select sum(B) where year(A) = 2024"). However, QUERY has a steeper learning curve and may be overkill for simple sums.
Practical Examples with Real Data
Let's walk through a concrete example. Suppose you have a spreadsheet with dates in A2:A10 and sales amounts in B2:B10:
A B
1 Date Amount
2 2024-01-05 100
3 2024-01-15 150
4 2024-02-01 200
5 2024-02-10 250
6 2024-03-01 300
7 2024-03-15 350
8 2024-04-01 400
9 2024-04-15 450
10 2024-05-01 500
To sum all sales in the first quarter (Jan-Mar 2024), use:
=SUMIFS(B2:B10, A2:A10, ">=2024-01-01", A2:A10, "<=2024-03-31")
This returns 100+150+200+250+300+350 = 1350. To sum sales after April 1, 2024, use =SUMIF(A2:A10, ">2024-03-31", B2:B10), which returns 400+450+500 = 1350 as well (coincidentally). To sum sales on the 15th of any month, you'd need an array formula, but for a single date, =SUMIF(A2:A10, "2024-02-15", B2:B10) returns 250.
Alternatives and Advanced Tips
If you need to sum based on a date that is relative to today (e.g., last 30 days), you can use the TODAY function in the criterion. For example, to sum amounts from the last 30 days:
=SUMIF(A2:A100, ">="&TODAY()-30, B2:B100)
This sums all amounts where the date is on or after 30 days before today. Note that TODAY() is volatile and recalculates when the sheet changes.
Another alternative is the FILTER function combined with SUM: =SUM(FILTER(B2:B100, A2:A100 >= DATE(2024,1,1), A2:A100 <= DATE(2024,1,31))). This is more flexible for complex conditions but can be slower on large datasets.
For date ranges that cross years, ensure your criteria are correct. For example, to sum all sales in 2024, use =SUMIF(A2:A100, ">=2024-01-01", B2:B100) - SUMIF(A2:A100, ">=2025-01-01", B2:B100) or =SUMIFS(B2:B100, A2:A100, ">=2024-01-01", A2:A100, "<2025-01-01").
Frequently Asked Questions
Why does my SUMIF return 0 when I use a date?
This usually happens because the dates in your range are stored as text, or the criterion is not recognized as a date. Check that the date cells are formatted as dates (Format > Number > Date). If they are text, convert them using DATEVALUE. Also ensure you use quotes around the date in the criterion, like "2024-01-01", not just 2024-01-01.
Can I use SUMIF with a date range like "between Jan 1 and Jan 31"?
No, SUMIF only handles one condition. Use SUMIFS with two criteria (>= and <=) as shown above. Alternatively, use QUERY or FILTER.
How do I sum by month in Google Sheets?
You can use a helper column with the MONTH function (e.g., =MONTH(A2)) and then SUMIF on that column. Or use QUERY to group by month without a helper column. The QUERY formula is =QUERY(A1:B100, "select month(A)+1, sum(B) group by month(A)").
What's the difference between SUMIF and SUMIFS?
SUMIF takes a single criterion, with arguments in the order: range, criterion, sum_range. SUMIFS takes multiple criteria, with the sum_range first, then pairs of criteria_range and criterion. SUMIFS is available in Google Sheets and is more flexible.
Can I use a cell reference for the date in SUMIF?
Yes, for an exact match you can reference the cell directly, like =SUMIF(A:A, C1, B:B). For a comparison, concatenate the operator with the cell reference using &, like =SUMIF(A:A, ">"&C1, B:B).
Does SUMIF work with dates in different time zones?
Google Sheets stores dates as serial numbers without time zone information. If you enter dates as text, they are interpreted in the spreadsheet's time zone. For consistent results, use the DATE function or ensure your date cells are actual date values, not text.
Related
- Generate 2 Random Numbers in Python: Easy Steps
- DEC2OCT in Google Sheets: Formula & Examples
- Google Sheets String Match: How to Find Matches
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Excel Goal Seek vs Solver: Which Tool Should You Use?Use Goal Seek when you know the result you want from one formula and need Excel to find…
- Excel Open Corrupted File? Recovery Steps That WorkTo open a corrupted workbook in Excel for Microsoft 365 on Windows, make a copy of the file,…
- How to Convert an Excel Sheet to WordTo convert an Excel sheet to Word, select the cells you want in Excel, copy them, then paste…
- SUMIF Negative Numbers in Google Sheets: Syntax & ExamplesTo sum values that are negative in Google Sheets, use =SUMIF(A2:A100,"<0",B2:B100). This example checks A2:A100 for numbers below…
- How to Enable Track Changes in Microsoft Word DocumentsTo enable Track Changes in Word, open the document, select the Review tab, and switch on Track Changes.…
- How to Make a Flowchart in Word Easily, Step by StepTo make a flowchart in Microsoft Word, choose Insert > Shapes, select a shape from the Flowchart section,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.