Sub topic 6
Matching text and numbers exactly
This chapter assumes you can enter and copy formulas, know the difference between relative and absolute references, and have used SUM, COUNT, and AVERAGE. It uses the sample sales layout, with headers in row 1 and data in rows 2 to 100.
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 GiftWhat an exact-match criterion is
A criterion is the test that decides whether a row counts. The simplest criterion is a plain value, such as the text West or the number 1200. A row passes when the cell in the criteria range equals that value.
=SUMIFS(D2:D100, B2:B100, "West")On the sample rows, this adds 1200 and 310 and returns 1510. The East and North rows fail the test, so their amounts are skipped.
=COUNTIFS(D2:D100, 300)This counts the rows where Amount is exactly 300. A number criterion needs no quotes. On the sample rows it returns 1, for the East monitor.
How the match is decided
The *IFS functions compare each cell in the criteria range with your value. Three rules cover most behavior.
- The whole cell must match. The criterion "West" does not match "West Coast" or "Northwest".
- Letter case is ignored. "west", "WEST", and "West" all match the same cells.
- Text that looks like a number is treated as that number. The criterion 100 matches a cell holding the number 100 and a cell holding the text "100".
The last rule is a convenience, but it hides a trap. If numbers were imported as text, a criteria match can still succeed. A sum of those same numbers will not, because the sum range ignores text values. Matching on the criteria side does not fix a bad sum range.
The diagram below shows the checks applied to each row.
Writing the criterion
Text needs quotes
Text typed inside a formula must be in double quotes. Without them, Excel reads West as a name and returns #NAME?.
=SUMIFS(D2:D100, B2:B100, "West")Numbers do not
Numbers can be typed directly. These two formulas give the same result:
=COUNTIFS(D2:D100, 300)
=COUNTIFS(D2:D100, "300")The explicit equals form
A criterion that is just a value is treated as if it began with "=". You can write the equals sign yourself, which makes the intent clear when the formula is read later.
=COUNTIFS(B2:B100, "=West")This behaves the same as "West". The explicit form becomes important once you meet comparison operators, which are covered in the next chapter.
Taking the value from a cell
You can put the value in a cell, such as G1 containing West, and pass the reference. No quotes are used, because the cell supplies the text.
=SUMIFS(D2:D100, B2:B100, G1)A later chapter covers this in detail. For now, note that the cell must hold exactly the text you want to match, including any stray spaces.
Combining an exact match with another pair
Each additional pair narrows the result. This counts West rows whose product is Laptop:
=COUNTIFS(B2:B100, "West", C2:C100, "Laptop")On the sample rows, only the first row passes both tests, so the result is 1. A row must pass every pair to be counted.
Common reasons an exact match fails
When a formula returns 0 or a total that is too small, the data usually differs from what you see on screen.
| Cause | What you see | How to check or fix |
|---|---|---|
| Extra spaces | "West " looks like West | Compare `=LEN(B2)` with the expected length, then clean with TRIM |
| Non-breaking spaces from web or system exports | TRIM does not remove them | Replace CHAR(160) with a normal space using SUBSTITUTE |
| Different spelling | "W." or "Wst" instead of West | Standardize the column, for example with a drop-down list |
| Numbers stored as text in the sum range | Total is too small or 0 | Convert the column to real numbers |
| Displayed value differs from stored value | 1200 shown, 1199.996 stored | Check the cell in the formula bar, or round the source values |
| Wildcard characters in the data | A value such as "A*B" matches more than expected | Put ~ before the character, as in "A~*B" |
Errors that come from the criterion itself
- #NAME? means text was typed without quotes.
- #VALUE! appears if a criterion string is longer than 255 characters. This is rare with exact matches, but it can happen when a long string is built by joining pieces together.
- #VALUE! also appears when the ranges are different sizes. Each range in a call must have the same number of rows and columns. A formula such as
=SUMIFS(D2:D100, B2:B99, "West")fails for this reason.
Putting it together
This formula adds Amount for West rows where the product is exactly Monitor:
=SUMIFS(D2:D100, B2:B100, "West", C2:C100, "Monitor")On the sample rows, only the 2025-02-02 row passes both tests, so the result is 310. To get an average instead, use the same pairs with AVERAGEIFS and the same first argument. Remember that AVERAGEIFS returns #DIV/0! when no row passes.
=AVERAGEIFS(D2:D100, B2:B100, "West", C2:C100, "Monitor")Summary
- A plain value in a criterion matches whole cells and ignores letter case.
- Text needs double quotes and numbers do not.
- A number-like text string matches both numbers and text numbers.
- Wrong results usually come from hidden spaces, text-formatted numbers, or ranges of different sizes.
Exercise
A column B holds regions, but COUNTIFS(B2:B100, "West") returns 0 even though several cells look like West. Name two likely causes and one formula that helps confirm the first.
Show answer
Likely causes are leading or trailing spaces (including non-breaking spaces from an export) and a different spelling of the word. To confirm the first, enter =LEN(B2) next to a suspect cell. A value of 4 means a clean West. A larger number means hidden characters. Clean the column with TRIM, or with SUBSTITUTE(B2, CHAR(160), " ") when non-breaking spaces are present.
Exercise
Using the four sample rows, what does =COUNTIFS(B2:B100, "west", C2:C100, "Laptop") return, and why does the lowercase "west" not cause a problem?
Show answer
It returns 1. Only the 2025-01-05 row is both West and Laptop. Matching ignores letter case, so "west" matches "West".