Sub topic 2
Building monthly roll-ups from a ledger
This chapter assumes you can enter formulas, understand relative and absolute references, and have a ledger with one transaction per row. In the examples, column B holds the account, column D the posting date, and column F the amount.
A monthly roll-up totals many ledger rows into one figure per account per month. SUMIFS does this. It takes the sum range first, then pairs of criteria ranges and criteria.
=SUMIFS(Data!$F$2:$F$5000, Data!$B$2:$B$5000, $A5, Data!$D$2:$D$5000, ">="&C$3, Data!$D$2:$D$5000, "<="&EOMONTH(C$3,0))Cell C$3 holds the first day of the month. The $A5 anchor keeps the account fixed while the formula copies across and down. The bounded range to row 5000 leaves room for new ledger rows.
What an exact-match lookup does
An exact-match lookup finds the one row whose key equals the search value. A key is a unique identifier, such as an account code. If no row matches, the lookup reports that fact instead of returning a near match.
XLOOKUP: lookup array, return array
XLOOKUP takes a lookup value, a lookup array (the column to search), and a return array (the column to read from).
=XLOOKUP($A5, Assumptions!$B$3:$B$12, Assumptions!$C$3:$C$12)XLOOKUP options for missing keys and match modes
The fourth argument supplies the text to show when no key matches. Without it, a miss returns #N/A, which can hide a broken link.
| Argument | Value | Effect |
|---|---|---|
| if_not_found | "Missing assumption" | Returned when no key matches |
| match_mode | 0 | Exact match (default) |
| match_mode | -1 | Exact match, or the next smaller item |
| search_mode | -1 | Searches from the last row upward |
=XLOOKUP($A5, Assumptions!$B$3:$B$12, Assumptions!$C$3:$C$12, "Missing assumption", 0)MATCH: finding a key's position
MATCH returns the position of a key within a range, counting from 1. The third argument 0 requests an exact match.
=MATCH($A5, Assumptions!$B$3:$B$12, 0)INDEX: returning the value at a position
INDEX returns the value at a given position in a range.
=INDEX(Assumptions!$C$3:$C$12, 3)Combined with MATCH, INDEX becomes a lookup that works in every Excel version:
=INDEX(Assumptions!$C$3:$C$12, MATCH($A5, Assumptions!$B$3:$B$12, 0))Exercise:
Exercise
The ledger has accounts in column B and amounts in column F. Write a formula that totals column F for the account in cell A5, across all rows up to row 5000.
Show answer
=SUMIFS(Data!$F$2:$F$5000, Data!$B$2:$B$5000, $A5)