Sub topic 15
Catching duplicates, missing keys, and unreconciled totals
This chapter assumes you can enter formulas, use absolute and relative references, and have already built SUMIFS roll-ups, XLOOKUP and INDEX with MATCH lookups, and tier lookups. Here you add checks that make those formulas fail loudly instead of quietly returning a wrong number.
Why lookups fail silently
A lookup formula usually does not crash when something is wrong. It returns a number that looks plausible. Three failures cause most of the damage:
- Duplicate keys. The key appears twice in the assumptions list. XLOOKUP and MATCH return the first match, so the second row is ignored without any warning.
- Missing keys. The key is spelled differently, has a trailing space, or was never added. Depending on how the formula is written, you get
#N/A, a default text, or, worst of all, a zero that flows into later calculations. - Unreconciled totals. A SUMIFS roll-up leaves out rows because an account name has a typo, a date falls outside the month columns, or the range stops before the data ends. Each month's formula still works, but the total is short.
The fix is to add a small check next to each lookup or roll-up. A check is a formula that returns 0 or TRUE when everything is fine and something else when it is not.
Checking for duplicate and missing keys with COUNTIF
COUNTIF counts how many times a key appears in a list. For a key that must appear exactly once, the count tells you everything:
- 0 means the key is missing.
- 1 means the key is unique and correct.
- 2 or more means the key is duplicated.
=COUNTIF(Assumptions!$B$3:$B$12, $A5)This formula counts how many times the key in $A5 appears in the assumptions list. Put it in a helper column beside the lookup, then flag anything other than 1:
=IF(COUNTIF(Assumptions!$B$3:$B$12, $A5)=1, 0, 1)This returns 0 for a good key and 1 for a bad one. Using 0 and 1 lets you add the whole helper column into a single total, which you can show at the top of the sheet.
COUNTIF has a trap. It treats * and ? in the key as wildcards, and it ignores case. A key such as Opex* would match every key beginning with Opex. Keep wildcard characters out of key lists. Also, COUNTIF treats text like "1" and the number 1 as equal, while XLOOKUP and MATCH do not. If a key is a number stored as text in one place and a real number in another, COUNTIF can report 1 while the lookup returns not found. Test the real lookup as well, as shown below.
Making the lookup itself report a missing key
XLOOKUP has a built-in not-found argument. Use text that is obviously not a value:
=XLOOKUP($A5, Assumptions!$B$3:$B$12, Assumptions!$C$3:$C$12, "Missing assumption")When the key is absent, the cell shows Missing assumption. Any formula that then multiplies this cell by something returns #VALUE!, which is what you want, because the error travels downstream and cannot be mistaken for a real result.
Do not set the not-found result to 0. A zero looks like a valid assumption (a growth rate of 0%), and the model will compute happily with it.
With INDEX and MATCH, the missing key shows up as #N/A from MATCH:
=INDEX(Assumptions!$C$3:$C$12, MATCH($A5, Assumptions!$B$3:$B$12, 0))Resist the habit of wrapping this in IFERROR(..., 0). IFERROR catches every error, including a broken reference or a range that no longer lines up, and replaces all of them with a number. If you need a fallback, use IFNA, which catches only #N/A, and make the fallback visible.
Checking that a roll-up reconciles
A SUMIFS roll-up splits the ledger into accounts and months. If it is complete, the sum of all the monthly cells equals the sum of the whole source column. The difference between the two should be zero:
=ROUND(SUM(C10:N10) - SUM(Data!$F$2:$F$5000), 2)Here C10:N10 is the total row of the monthly roll-up and Data!$F$2:$F$5000 is the amount column. ROUND to 2 decimals removes floating-point noise, such as 0.0000000001, which would otherwise make a correct model look broken.
When this check is not zero, the cause is almost always one of these:
| Symptom | Likely cause |
|---|---|
| Roll-up is lower than source | An account in the ledger is not in the row labels, or has a typo or trailing space |
| Roll-up is lower, only in some months | Dates outside the first and last month column, or dates stored as text |
| Roll-up is lower by a round number | A range ends before the last data row |
| Roll-up is higher than source | A row label appears twice, so the same account is totaled twice |
To find the missing rows, add a helper column in the Data sheet that checks whether each row's account exists in the roll-up labels:
=COUNTIF(Model!$A$5:$A$40, B2)Filter this column for 0. Those are the ledger rows the roll-up cannot see.
A check block that collects everything
Put all checks in one place, usually at the top of the model or on a dedicated Checks sheet. Each line gets a label, a formula that returns 0 when fine, and a status. The block below assumes the helper column for duplicate and missing keys is in Model!H5:H40.
=SUM(Model!$H$5:$H$40)This totals the bad-key flags. Combine the individual checks into one master flag:
=IF(AND(B3=0, B4=0, B5=0), "OK", "CHECK MODEL")Here B3, B4, and B5 hold the individual checks: bad keys, unreconciled total, and rows not matched. Link the master flag to the model's front page so no one reads results without seeing it.
Common mistakes
- Checking only the formula you wrote. A check that repeats the same logic as the formula it guards will make the same mistake. Reconcile against an independent source, such as the raw column total.
- Tolerance too loose. Allowing a difference of 1 or 10 hides real errors. Use rounding to cents and require exact zero.
- Hard-coded range ends.
$F$2:$F$5000works until row 5001 is pasted. Add a check that counts the data rows and compares it with the range limit, for example=COUNTA(Data!$B:$B)-1against 4999. Excel tables avoid this problem because their ranges grow with the data. - Hidden failure in IFERROR. If a check cell uses IFERROR to display 0, it can never fail. Keep checks free of error masks.
- Trailing spaces and inconsistent text.
"Rent "and"Rent"are different keys. Clean imported data with TRIM before it reaches the ledger, then let the checks catch what slips through.
Putting it together
A good order of work for any new lookup or roll-up is:
- Write the formula with a visible not-found result.
- Add a COUNTIF helper that confirms each key appears exactly once.
- Add a reconciliation line comparing the roll-up with the source total.
- Add all checks to the master flag.
- Break the model deliberately and confirm the flag changes.
These steps take a few minutes per model and prevent the most common reasons a financial model gives a wrong number with no visible sign.
Exercise
A monthly roll-up built with SUMIFS shows a total of 1,184,200 in its total row, but the SUM of the amount column in the Data sheet is 1,190,700. The reconciliation check returns -6,500. List two causes you would test first and how you would test each.
Show answer
First, an account in the ledger that is missing from the roll-up row labels, perhaps because of a typo or trailing space. Test it by adding a helper column in Data that uses COUNTIF against the roll-up labels, then filtering for 0 and checking whether those rows add up to 6,500. Second, dates outside the month columns, or dates stored as text, which the date criteria skip. Test it by filtering the Data sheet for dates before the first month start or after the last month end, and by using ISNUMBER on the date column to find text dates. A third cause worth checking is a range such as $F$2:$F$5000 that ends before the last data row.
Exercise
Why is =XLOOKUP($A5, Assumptions!$B$3:$B$12, Assumptions!$C$3:$C$12, 0) a poor way to retrieve a growth rate, and what should the fourth argument be instead?
Show answer
A not-found result of 0 looks like a valid growth rate of 0%, so a missing key flows into the model unnoticed. Use clear text such as "Missing assumption", so that downstream formulas return an error and the problem is visible.