Formulas are rules in disguise: reading a workbook as a dependency graph
=SUMIFS(D:D, A:A, A2) is a business rule written in coordinates. Translate the coordinates and the rule appears.
Every formula in a workbook is a business rule. It just names its inputs by position instead of by meaning. =SUMIFS(Lines!F:F, Lines!A:A, A2) says “an order’s subtotal is the sum of its lines”, but it says it in coordinates. Translate the coordinates and the rule appears, and so does the structure of the whole business.
Rules written in coordinates#
Coordinates are what make spreadsheets fast to build and hard to review. A reviewer reading =IF(K14>Rates!$B$3, K14*0.05, 0) has to go and find out what K14 is, what B3 on the Rates sheet holds, and whether row 14 is the only row it applies to. Insert a row above B3 and the formula is still syntactically perfect and quietly wrong.
The same rule written against meaning reads itself: if the order’s subtotal is above the discount threshold, the discount is 5% of the subtotal. Nothing about it depends on which row anything is in.
Here are three formulas from the example operations workbook Tavuni ships with, next to the rules its compiler read out of them:
| Field | Excel | Rule |
|---|---|---|
| Order.subtotal | =SUMIFS(OrderLines!$H$4:$H$383,OrderLines!$B$4:$B$383,A4) | SUM(OrderLine.lineTotal WHERE OrderLine.orderId = Order.orderId) |
| Order.taxRate | =IFERROR(VLOOKUP(E4,TaxRates!$A$4:$B$9,2,FALSE),DefaultTaxRate) | IFERROR(LOOKUP(TaxRate WHERE TaxRate.country = Order.shipCountry).taxRate, Setting.DefaultTaxRate) |
| Order.freight | =IF(D4="Cancelled",0,MAX(FreightMinimum,ROUND(I4*FreightRate,2))) | IF(Order.status = "Cancelled", 0, MAX(Setting.FreightMinimum, ROUND(Order.netAmount * Setting.FreightRate, 2))) |
From cells to a graph#
Excel can already show you one formula’s inputs (Trace Precedents) and the cells that read it (Trace Dependents). Do that for every formula at once and you have a dependency graph of the workbook. On its own it is a tangle of cells. Three moves turn it into a picture of the business:
- Rows become records. A block of rows with a header row is a list of things: orders, lines, customers.
- Columns become fields. When the same formula is copied down a column, it is one rule applied to every record, not hundreds of separate formulas.
- Lookups become relationships. A
VLOOKUP,XLOOKUPorINDEX/MATCHkeyed on an id column is one kind of record pointing at another: an order line pointing at a product.
Done for the example workbook, those moves take 2,993 formulas down to 7 record types, 6 relationships and 18 calculated fields. Thousands of cells become a model that fits on one screen.
A workbook with thousands of formulas often holds a few dozen rules, copied down a few dozen columns.
What the graph shows you#
Once the formulas are a graph of named things, questions that were hard become easy to answer:
- What are the real inputs? The typed-in values that everything else is built from. These are what people should be entering in an application, and nothing else.
- Where is the single point of failure? One hard-coded rate in one cell, read by four hundred formulas, is a rule that deserves a name and an owner.
- Is anything circular? A value that eventually depends on itself. Excel can be told to tolerate this; a system of rules should refuse it.
- What is dead? Formulas that compute something nothing reads. Often an old report; sometimes a rule everyone thinks is still applied.
- What is hidden? Hidden sheets that take part in the calculation are part of the rules, whether anyone remembers them or not.
Where reading stops#
Not everything in a workbook can be read this way, and a tool that pretends otherwise is guessing. Be suspicious of any that never says “I cannot read this”.
- References computed while running.
INDIRECTandOFFSETbuild a reference from text or arithmetic, so which cells they read is only known when they run. - Spilled arrays. Dynamic array formulas fill neighbouring cells whose extent depends on the data.
- Free-form layouts. A sheet laid out like a printed form, rather than a table, has no rows to turn into records without a person’s help.
- Macros. VBA is a program, not a formula. Its rules have to be described, not read.
See how one order’s total is built from the example workbook, rule by rule, on the spreadsheets page, or pick any rule and follow what it reads on the home page.