Sub topic 13
Keeping formulas short and avoiding risky constructs
This chapter assumes you can build multi-sheet Excel workbooks, understand relative and absolute references, and use IF, SUM, AND, ABS and EOMONTH. It also assumes you already follow the rule of one formula per row and one calculation per row.
Why formula length matters
A long formula is hard to read, hard to check and easy to break. The FAST Standard asks for transparent logic. Short formulas support that goal because a reviewer can see what each one does without unpicking several steps at once.
Most modelling guidelines set a rough limit on formula length, often one line of the formula bar. The exact number matters less than the habit. If you need to scroll or wrap the formula bar, split the calculation across rows.
A short formula has three benefits:
- A reviewer can check it by reading it once.
- When a number looks wrong, you can see which step caused it.
- A change affects one step, not a whole nest of logic.
Splitting a long formula into steps
Consider a single cell that works out interest on a loan, only while operations run, with a cap on the amount.
F30: =IF(AND(F$6>=Inputs!$D$8,F$7<=Inputs!$D$9),MIN(F28*Inputs!$D$14/12,Inputs!$D$15),0)This formula mixes three ideas: a timing test, an interest calculation and a cap. Each idea can have its own row.
F10: =IF(AND(F$6>=Inputs!$D$8,F$7<=Inputs!$D$9),1,0)
F29: =F28*Inputs!$D$14/12
F30: =MIN(F29,Inputs!$D$15)
F31: =F30*F10
' Row 10: Operations flag (1 while operations run)
' Row 28: Opening balance
' Row 29: Uncapped interest
' Row 30: Interest after cap
' Row 31: Interest charged while operating
' Inputs!D14: Annual interest rate
' Inputs!D15: Maximum interest per periodEach row now has a label, so a reviewer can follow the logic from top to bottom. The extra rows cost almost nothing. The flag in row 10 is also reused by other calculations, which removes repeated date logic.
Risky constructs to avoid
Some Excel features make a model harder to audit or easier to break. The table lists common ones and safer options.
| Construct | Why it is risky | Safer option |
|---|---|---|
| Deeply nested IF | Hard to read, and the order of tests matters | Separate flag rows, or a lookup table |
| OFFSET and INDIRECT | Volatile, so they recalculate on every change, and they hide dependencies from trace tools | INDEX, or a direct reference |
| Merged cells | Break copy and paste, sorting and range selection | Center across selection |
| Hardcoded numbers in formulas | Hidden assumptions that no one updates | A labelled input cell |
| Whole-column references in SUM | Can pick up totals or notes added later | A fixed range, or a clear total row |
| Mixed units in one formula | Silent scaling errors | One unit per row, with a conversion row |
| IFERROR wrapped around everything | Hides real errors and returns plausible but wrong numbers | Fix the cause, and trap only expected errors |
| Links to external workbooks | Break when files move, and values can go stale | Import data into an input sheet |
Nested IF statements
A nested IF is a formula where one IF sits inside another. Two levels can be fine. Beyond that, the reader has to hold every branch in their head.
F20: =IF(F10=1,IF(F11=1,F12,F13),IF(F14=1,F15,0))A cleaner approach is to calculate each condition on its own row, then combine them with simple multiplication.
F16: =F10*F11
F17: =F10*(1-F11)
F18: =(1-F10)*F14
F20: =F16*F12+F17*F13+F18*F15Now every row is a plain test or a plain product. A reviewer can check each case against the original logic.
Volatile functions
A volatile function recalculates whenever anything in the workbook changes. OFFSET, INDIRECT, TODAY, NOW and RAND are volatile. In a large model this slows recalculation. OFFSET and INDIRECT also hide dependencies, so Excel's Trace Precedents tool cannot reliably show where a number comes from.
Where you only need a value from a position in a range, use INDEX.
F25: =INDEX(Inputs!$F$20:$Z$20,F$8)
' Row 8: Period counter (1, 2, 3 ...)
' Inputs!F20:Z20: Annual assumptions listed by periodINDEX is not volatile, and the range it reads is visible in the formula.
IFERROR and error masking
IFERROR returns a chosen value when a formula errors. Wrapping a whole calculation in it hides problems. A broken link that returns zero looks like a valid result.
Use it only where an error is expected and the fallback is correct, and keep the test narrow. A divide by zero in a margin calculation is an example.
F40: =IF(F38=0,0,F39/F38)
' Row 38: Revenue
' Row 39: Operating profit
' Row 40: Operating marginThis tests the one condition you expect. Any other error still shows, so you notice it.
Hardcodes inside formulas
A hardcode is a number typed directly into a formula, such as =F20*1.2. The reader cannot tell what 1.2 means, and it will not change when the assumption changes. Move the number to a labelled cell on the inputs sheet and refer to it.
F22: =F20*(1+Inputs!$D$16)
' Inputs!D16: Sales tax rateThere are a few acceptable constants. These include 0 and 1 in logic tests, 12 for months in a year when the model is monthly, and 100 for percentages. Even these are better as named constants if they appear often.
A decision guide
When you meet a long or complex formula, ask these questions in order:
- Does it contain more than one calculation? If so, split it across rows.
- Does it contain a typed number? If so, move the number to an input.
- Does it contain a volatile or hidden-dependency function? If so, replace it with INDEX or a direct reference.
- Is an error being hidden? If so, narrow the test.
- Can a colleague check it in about ten seconds? If not, simplify further.
Trade-offs and edge cases
Short formulas add rows, and a model with many rows can feel long. The FAST view is that length down the page is cheaper than complexity in one cell. You can group or outline helper rows so the sheet stays tidy.
Some functions are hard to avoid. SUMPRODUCT can replace several helper rows, but it is harder to read. Use it when the alternative is a large block of repetitive rows, and add a comment row that states what it does.
Do not split a formula so far that the meaning is lost. A row that only holds =F20 adds nothing. Each row should carry a meaningful step with a label.
Finally, a short formula is not automatically correct. Combine these habits with integrity checks, so a wrong result still triggers a flag.
Exercise
A cell contains =IFERROR(IF(AND(F$6>=Inputs!$D$8,F$7<=Inputs!$D$9),F20F211.2,0),0). List the problems and describe how you would restructure it.
Show answer
Problems: (1) the timing test, the calculation and the tax are combined in one cell; (2) 1.2 is a hardcode with no label; (3) IFERROR wraps everything, so any error, such as a broken reference, returns 0 and looks valid. Restructure: put the timing test in a flag row (=IF(AND(F$6>=Inputs!$D$8,F$7<=Inputs!$D$9),1,0)); put 1.2 on the inputs sheet as a labelled rate; calculate pre-tax revenue in one row (=F20F21); calculate the final value in another (=F22(1+Inputs!$D$16)*F10); and remove IFERROR so errors show.
Exercise
Why is INDEX preferred over OFFSET for picking a value by position?
Show answer
OFFSET is volatile, so it recalculates with every change and slows large models, and it hides its precedents from trace tools. INDEX is not volatile and shows the range it reads in the formula.