Google Sheets SUMIF Contains Partial Text: How-To Guide
In this article
To sum values in Google Sheets where a text column contains a specific substring, use SUMIF with wildcards: =SUMIF(range, "*text*", sum_range). The asterisks act as wildcards that match any characters before or after your text, so the formula adds up every row whose text cell contains that substring anywhere. This works for case-insensitive partial matches and is the standard method for conditional sums based on partial text.
What You'll Need
- A Google account with access to Google Sheets (free with any Google account).
- A spreadsheet with at least one column of text to search and one column of numbers to sum.
- Basic familiarity with entering formulas (starting with
=).
Step-by-Step
- Open your spreadsheet in Google Sheets and identify the columns you will use. For example, column A might contain product descriptions and column B the corresponding sales amounts.
- Click an empty cell where you want the result to appear.
- Type the SUMIF formula using this pattern:
=SUMIF(A2:A100, "*text*", B2:B100). ReplaceA2:A100with the range containing the text,textwith the substring you want to match, andB2:B100with the range of numbers to sum. The asterisks are essential: without them, SUMIF looks for an exact match. - Press Enter. The cell will display the total of all numbers in the sum range where the corresponding text cell contains your substring.
- Adjust for case sensitivity if needed. SUMIF is not case-sensitive by default, so "apple" and "Apple" both match. If you need case-sensitive partial matching, use
SUMPRODUCTwithSEARCHorFINDinstead, but that is beyond this basic guide. - Copy the formula down or across if you want to calculate multiple partial-text sums. Use relative references (like A2:A100) so the ranges adjust, or absolute references (like $A$2:$A$100) to keep them fixed.
Common Mistakes
- Forgetting the asterisks. Using
"text"instead of"*text*"will only sum cells that exactly equal "text", not cells that contain it. - Mismatched range sizes. The sum_range must be the same size as the criteria range. If A2:A100 is 99 rows, B2:B100 must also be 99 rows; otherwise SUMIF may return incorrect results or an error.
- Including the header row. If your range includes a header like "Product", it won't match the wildcard pattern unless the header contains the substring, but it's safer to start ranges at row 2.
- Using wildcards with numbers. SUMIF wildcards work on text. If your criteria range contains numbers, wildcards won't match them; convert numbers to text or use a different approach.
- Assuming case sensitivity. SUMIF ignores case, so "*apple*" matches "Apple" and "APPLE". If you need exact case, you must use a different function.
Tips
- Use cell references for the substring to make the formula dynamic:
=SUMIF(A2:A100, "*"&C1&"*", B2:B100)where C1 contains the text to search for. This lets you change the search term without editing the formula. - Combine with other functions like
SUMIFSto add multiple criteria, e.g., sum if column A contains "apple" and column C equals "North". - Test with a small range first to confirm the wildcard behavior before applying to large datasets.
- Remember that wildcards also match empty strings if you use
"*"alone; always include your substring between asterisks. - Use
FILTERorQUERYfor more complex partial-text sums if you need to sum based on multiple conditions or return a list of matching rows.
Troubleshooting
If your SUMIF formula returns 0 or an unexpected result, check these common issues:
- Verify the ranges: Ensure the criteria range and sum range are the same size and correctly aligned. A quick way is to select each range and check the row count in the bottom right of the sheet.
- Check for extra spaces: Text cells with leading or trailing spaces may not match your substring. Use
TRIMin a helper column or adjust the wildcard pattern to include spaces if needed. - Confirm wildcard characters: The asterisk (*) is the wildcard for any number of characters; the question mark (?) matches exactly one character. Make sure you're using the correct one.
- Look for errors: If you see
#VALUE!or#N/A, check that the sum range contains only numbers and that the criteria range is text. - Test with a simple case: Create a small test table with known values to isolate whether the issue is with the formula or the data.
- Use
SUMPRODUCTas an alternative:=SUMPRODUCT(--ISNUMBER(SEARCH("text", A2:A100)), B2:B100)can sum based on partial text and is case-insensitive. This is useful if SUMIF with wildcards isn't working for some reason.
Frequently Asked Questions
Can SUMIF match partial text?
Yes, by using wildcards: =SUMIF(range, "*text*", sum_range). The asterisks allow any characters before and after the text.
Is SUMIF case-sensitive?
No, SUMIF is not case-sensitive. "*apple*" will match "Apple", "APPLE", and "apple".
What if my text contains wildcard characters like * or ??
If your search text includes literal asterisks or question marks, you need to escape them with a tilde (~). For example, to match "a*b", use "*a~*b*".
Can I use SUMIF with multiple partial text criteria?
Yes, use SUMIFS: =SUMIFS(sum_range, criteria_range1, "*text1*", criteria_range2, "*text2*").
Why does my SUMIF return 0 even though there are matches?
Check that the sum range contains numbers (not text), the ranges are the same size, and the wildcards are correctly placed. Also ensure there are no extra spaces in the text cells.
Can I sum based on partial text in a different sheet?
Yes, reference the other sheet in the ranges, e.g., =SUMIF(Sheet2!A2:A100, "*text*", Sheet2!B2:B100).