Practice problems / Data Cleaning

Vendor spend when the names carry stray spaces (SUMIF)

Medium Data Cleaning
Description
Hints 0/4
Solutions 2
–
Test case
1
2
3
Reset
Submit
fx
A
B
C
D
E
F
G
1
2
3
4
5
6
7
8
9
10
Loading interactive spreadsheet...
Preparing grid cells and formula calculation engine
○ Ready Enter formula in highlighted cells, then click Submit.

The problem

Problem statement

The AP export in A2:C7 was typed by three different people: the same vendor shows up as Acme Corp, Acme Corp , Acme Corp and ACME CORP. Finance wants one number per vendor and will not let you edit the sheet. Put the paid total for the vendor named in E2 into the Paid total cell F2.

You cannot clean column A — the spacing and capitals stay. The formula itself has to survive the dirty key column.

Problem data

Show the sheet as a table (selectable, copyable)
The exercise data, as a table
ABCEF
1 VendorInvoiceAmountVendorPaid total
2 Acme CorpINV-10011200Acme Corp
3 Acme Corp INV-1002640
4 GlobexINV-1003900
5 Acme CorpINV-1004380
6 InitechINV-1005450
7 ACME CORPINV-1006260

Notes

An exact criteria like =SUMIF(A2:A7, E2, C2:C7) silently skips every cell with a leading or trailing space, so the total comes out short with no error. Two ways out: match on a substring with wildcards ("*"&E2&"*") or strip the padding inside the formula with SUMPRODUCT and TRIM. SUMIF also ignores case, which is why ACME CORP still counts.

How to approach

Your answer goes in F2. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.

  1. Target cell is F2
  2. The vendor names are in A2:A7 and the amounts in C2:C7
  3. Try the exact criteria first and compare with the sheet — count how many Acme Corp rows the answer missed, then look closely at the spaces around them
  4. Shape: =SUMIF(?, "*"&?&"*", ?) or =SUMPRODUCT((TRIM(?) = ?) * ?)

Official solutions

Show 2 solutions — try it yourself first

Approach 1: wildcard contains-match

=SUMIF(A2:A7, "*"&E2&"*", C2:C7)

"*"&E2&"*" turns the name into a contains-match, so a cell with a leading or trailing space still qualifies. Fast to write; the caveat is that a longer name containing the same text (e.g. 'Acme Corp Ltd') would also be picked up.

Approach 2: TRIM the key column with SUMPRODUCT

=SUMPRODUCT((TRIM(A2:A7) = E2) * C2:C7)

TRIM removes the leading and trailing spaces from every key first, then the equality test is exact, so 'Acme Corp Ltd' can never sneak in. The boolean array multiplied by C2:C7 keeps only the matching amounts — the robust version when the column is genuinely dirty.

Function guide

Related practice

FAQ

Why does an exact SUMIF miss rows that are clearly there?

Because a leading or trailing space is part of the cell value. "Acme Corp" and " Acme Corp" are different strings, so the equality test fails and the row is dropped without any error message. Look for the subtle indent, or match with wildcards instead.

Should I use wildcards or TRIM for dirty vendor names?

Wildcards are quicker but match any cell containing the text, including a longer vendor name that embeds it. TRIM inside SUMPRODUCT is exact after cleaning, so it cannot over-count. If the list can contain 'Acme Corp' and 'Acme Corp Ltd', prefer TRIM.

Does SUMIF care about UPPER and lower case?

No. SUMIF and SUMIFS compare text case-insensitively, so ACME CORP matches 'Acme Corp'. If you truly need a case-sensitive total, use SUMPRODUCT with the EXACT function.