Sub topic 2
Totaling Many Rows or Fetching One Value
Every number in a financial model reaches its cell in one of two ways. The formula either adds up many rows, or it retrieves one stored value. Picking the wrong way gives results that look reasonable and are wrong. This chapter teaches you to tell the two tasks apart before you write any formula.
This chapter assumes you can enter formulas, you understand relative and absolute references, and you have seen a simple budget or income statement layout. It also assumes the data is already in a flat table, one record per row, as the previous chapter described.
Two questions a model asks
A model cell asks one of two questions.
- Aggregation: "What is the total of all rows that match these conditions?" The answer can come from zero, one, or hundreds of rows. Example: total rent expense for March.
- Lookup: "What is the one value stored for this key?" The answer comes from exactly one row. Example: the sales tax rate for the key
Tax rate.
A key is the label that identifies a record, such as an account name or an assumption name. In a lookup, the key should identify exactly one row. In an aggregation, a key such as an account name is expected to match many rows.
The two questions use different functions:
| Question | Typical source | Function family | Number of rows expected |
|---|---|---|---|
| Total by account, category, or month | Ledger or transaction data | SUMIFS | Zero to many |
| Retrieve an assumption, rate, or label | Assumptions or rate table | XLOOKUP, or INDEX with MATCH | Exactly one |
A worked example
Suppose the model has a Data sheet holding the ledger. Column B is the account, column C the category, column D the date, and column F the amount.
| Row | B: Account | C: Category | D: Date | F: Amount |
|---|---|---|---|---|
| 2 | Office rent | Opex - Premises | 2026-01-01 | 4,000 |
| 3 | Software | Opex - IT | 2026-01-09 | 650 |
| 4 | Office rent | Opex - Premises | 2026-02-01 | 4,000 |
| 5 | Software | Opex - IT | 2026-02-11 | 700 |
The report sheet lists account names in column A. To fill in the total for the account named in $A5, you add every row whose account matches:
=SUMIFS(Data!$F$2:$F$5000, Data!$B$2:$B$5000, $A5)For Office rent, this returns 8,000 because two rows match. The formula would still work if there were twenty matching rows or none. With none, it returns 0.
Now the Assumptions sheet. Column B holds keys such as Tax rate and Payment days. Column C holds each key's value. To fetch the value for the key in $A5:
=XLOOKUP($A5, Assumptions!$B$3:$B$12, Assumptions!$C$3:$C$12, "Missing assumption")This returns one value, for example 0.20. It never adds anything. If the key is absent, it shows the text Missing assumption.
A different formula could do the same job here, and that is where the risk lies. The next sections show why.
Why using the wrong one is dangerous
Both mistakes are silent. Excel does not raise an error, and the cell shows a plausible number.
Using a lookup on ledger data
A lookup returns the first matching row and stops. Point XLOOKUP at the ledger for Office rent and it returns 4,000, the January row. The correct total is 8,000. The model understates rent, and nothing signals a problem. The error grows as more months are added, but the first row always looks fine.
Using SUMIFS as a lookup
SUMIFS can fetch an assumption if the key is unique, because the sum of one row is that row's value. Many modelers do this out of habit. It fails in three ways:
- A missing key returns 0, not an error. A tax rate of 0 looks like a deliberate input. The model then calculates tax of zero.
- A duplicated key adds the values. If
Tax rateappears twice, each entered as 0.20, SUMIFS returns 0.40. A lookup would return 0.20 and ignore the second row. Both results are wrong, but the SUMIFS one is more visible, and the lookup one hides the duplicate. - Text values return 0. SUMIFS only adds numbers. A text assumption such as a currency code or a scenario name cannot be retrieved this way.
Deciding which task you have
Ask two questions about the cell you are building.
- Should the answer change if another matching row is added to the source? If yes, you are aggregating. A new ledger line for rent should change the rent total. If no, you are looking up. A second row for
Tax rateis a data error, not new information. - Is the result always a number that can be added? Aggregation requires numbers. Lookups can return text, dates, or numbers.
The two branches end in different checks. An aggregation is verified by reconciling its total with the source data. A lookup is verified by counting how often its key appears.
The checks that match each task
For a lookup, count the key. A result of exactly 1 means the key is present once:
=COUNTIF(Assumptions!$B$3:$B$12, $A5)A result of 0 means a missing key. A result of 2 or more means a duplicate, and the lookup is quietly using only the first one. Put this check next to each assumption, or in a column beside the assumptions list, so that an error is visible on the same row.
For an aggregation, compare the sum of your report with the sum of the source. The roll-up row here covers months in C10:N10:
=ROUND(SUM(C10:N10) - SUM(Data!$F$2:$F$5000), 2)This should return 0. A nonzero result means some ledger rows were not captured. Common causes are an account name that is spelled differently in the ledger, a date outside the report year, or a row beyond the range's end. The ROUND to two decimals prevents tiny floating-point differences from showing as failures.
You will build both checks fully in a later chapter. For now, remember that each task type has its own check, and you should decide which one applies when you write the formula.
Edge cases to watch for
- Close names.
Office rentandOffice Rent(with a trailing space) are different keys to a lookup. SUMIFS treats the second as a non-match and silently leaves it out of the total. The reconciliation check catches this. - Blank criteria. If
$A5is empty, SUMIFS matches blank cells in the criteria range, not zero rows. A lookup on a blank key usually returns a not-found result. Neither is what you want, so keep report labels filled in. - Ranges that stop too early. A range ending at row 5000 ignores row 5001. Both functions behave this way. The reconciliation check also catches this for aggregations.
- Aggregating a single row on purpose. Totaling a single known transaction is still an aggregation. Use SUMIFS if the source is a ledger and more rows may appear later.
Exercise
A model has a Rates sheet listing Fuel surcharge once, with the value 0.035, and a Data ledger with 40 rows for the account Freight. For each of these two cells, say whether it is an aggregation or a lookup, and name the check you would add: (a) the total freight cost for the year, (b) the fuel surcharge used in a cost formula.
Show answer
(a) Aggregation. A new Freight row should change the answer, so use SUMIFS on the ledger, and check that the report total reconciles to the sum of the source amounts, for example with ROUND(SUM(report row) - SUM(source amounts), 2) returning 0. (b) Lookup. The surcharge is one stored value, and a second row would be a data error, so use XLOOKUP or INDEX with MATCH with a clear not-found result, and check with COUNTIF that the key Fuel surcharge appears exactly once.