Sub topic 13
Keeping Large Models Responsive
This chapter assumes you can build one-variable and two-variable data tables, that you know the TABLE array formula, and that you have used the Automatic except for Data Tables setting. Here you will learn why data tables slow a workbook down, how to estimate the cost before it hurts, and what to change when the model feels sluggish.
Why data tables are expensive
A data table does not use a clever shortcut. For every cell in the grid, Excel does the following:
- It writes the row and column values into the input cells.
- It recalculates every cell that depends on those inputs.
- It reads the output formula and stores the result in the grid cell.
- It restores the original input values.
So the cost of a table is roughly the number of grid cells times the cost of one full recalculation of the dependent part of the model.
A 5 by 5 table needs 25 recalculations. An 11 by 11 table needs 121. If the model takes 0.05 seconds to recalculate, the 121-cell table adds about 6 seconds each time it refreshes. A model that feels instant on its own can become slow once it holds several tables.
Estimating the cost before you build
Count three things:
- Grid cells. Rows times columns for a two-variable table, or the number of input values times the number of output columns for a one-variable table.
- Number of tables. Each table recalculates separately.
- Size of the dependency chain. This is how much of the model sits between the input cells and the output.
A rough budget is:
table time ≈ grid cells × time for one recalculation of the dependent chainYou can measure the second factor. Switch to manual calculation, change an input, and time how long F9 takes. Put the data tables in Automatic except for Data Tables mode first, so the measurement does not include them. That time is a reasonable estimate of one recalculation.
The following VBA macro times a calculation. It runs in the Visual Basic Editor (Alt+F11) after you insert a module.
Sub TimeRecalc()
Dim t As Double
Dim previousMode As XlCalculation
previousMode = Application.Calculation
Application.Calculation = xlCalculationManual
t = Timer
Application.Calculate
MsgBox "Recalculation took " & Format(Timer - t, "0.000") & " seconds"
Application.Calculation = previousMode
End SubRun it with the tables in place. If you have set Automatic except for Data Tables, Application.Calculate still refreshes the tables, so this shows the full cost of a manual refresh.
Reduce the cost of each recalculation
Because the table multiplies the cost of one recalculation, trimming that cost helps every cell of the grid.
Keep the dependency chain short
Excel only recalculates cells that depend on the input cells. Anything that does not depend on them is not repeated for each grid cell. Keep your sensitivity inputs close to the part of the model they affect, and avoid linking them to unrelated sections.
For example, a DCF with a WACC input and a terminal growth input recalculates the discounting and terminal value chain. It does not need to rebuild a 10-year operating forecast that depends on neither input. If the forecast does depend on them, because of circular links, the table pays for it on every cell.
Avoid volatile functions
Volatile functions recalculate on every calculation, whether or not their inputs changed. The common ones are OFFSET, INDIRECT, TODAY, NOW, RAND and RANDBETWEEN. Inside a data table, each grid cell triggers a recalculation, so volatile cells in the chain run again every time.
Replace them where you can:
| Volatile pattern | Non-volatile replacement |
|---|---|
| `OFFSET(A1, n, 0)` | `INDEX(A:A, n+1)` |
| `INDIRECT("Sheet1!A"&n)` | `INDEX(Sheet1!A:A, n)` |
| `TODAY()` in a valuation date | A hardcoded date input |
A hardcoded valuation date also makes the table reproducible. A TODAY()-based output changes from one day to the next, so you cannot compare a saved table with a later one.
Avoid whole-column ranges in heavy formulas
Functions such as SUMPRODUCT, SUMIFS and array formulas over whole columns (A:A) process over a million rows. Use bounded ranges or Excel Tables (structured references). Multiplied by 121 grid cells, the difference is large.
Remove circular references from the chain
Iterative calculation is slow, and each grid cell would run the iterations again. Interest on average debt balances is a common source. If your model has a circularity, consider a circuit-breaker switch or an algebraic solution. Also test that the table gives the same results as the model when you change the inputs by hand. Circular models can give unstable results inside data tables.
Reduce the number of recalculations
Use Automatic except for Data Tables
This setting is under Formulas > Calculation Options. With it, normal edits recalculate the model, but the tables wait until you press F9. It is the single most useful change for a slow workbook.
Remember the consequence: while the tables wait, they show stale values. After changing any input that affects them, press F9 before reading or copying a table. The base case check from earlier is a quick test for staleness. If =E5-B4 is not zero, the table needs a refresh, or something is broken.
Shrink the grid
Choose axis values that answer the question you are asking. A grid of 5 by 5 usually shows the pattern. A 21 by 21 grid has 441 cells and often shows nothing more. If you need fine detail in one region, build a second small table around that region rather than one large table.
Use one table for many outputs
A one-variable table can return several outputs at once. Put several output formulas in the top row, and Excel runs one recalculation per input value for all of them. Three separate tables of the same inputs would cost three times as much.
D3:D7 (rates): 0.045, 0.055, 0.065, 0.075, 0.085
E2: =B4 (monthly payment)
F2: =B4*B3*12 (total paid)
G2: =B4*B3*12-B1 (total interest)
Select D2:G7 > Data > What-If Analysis > Data Table
Column input cell: B2
Result in E3:G7: {=TABLE(,B2)}This costs 5 recalculations for 15 results. Three separate tables would cost 15.
A two-variable table can show only one output, so for several outputs you need several tables. In that case, keep each one small.
Limit the number of tables
Tables that nothing reads still cost time. When you finish a piece of analysis, delete tables that nobody uses, or move them to a separate workbook that you open when needed.
Workbook-level settings
Other settings affect the whole application and are easy to forget.
- Multi-threaded calculation. Under File > Options > Advanced > Formulas, keep "Enable multi-threaded calculation" on. It speeds up ordinary recalculation, though data tables may benefit less than normal formulas because the substitution steps happen in sequence. Do not rely on it to rescue a large table.
- Other open workbooks. Excel's calculation setting is shared by all open workbooks in a session. If you open a workbook set to manual, it can switch your session to manual. Check the status bar for "Calculate" after opening files.
- Linked workbooks. Links to closed files make recalculation slower. Paste values for data that does not change, or consolidate the inputs.
- Add-ins. Some add-ins force recalculation or change the calculation mode. If performance changes suddenly, disable add-ins one at a time.
Freezing results when you no longer need them to update
Sometimes you only need a table's results for a presentation or a memo. You can copy the grid and use Paste Special > Values. This replaces the TABLE formula with static numbers, which removes the cost entirely.
Do this on a copy of the sheet, or keep a version of the workbook with live tables. After pasting values, the numbers no longer respond to input changes. Label the pasted block clearly, with the date and the base case inputs, so nobody mistakes it for a live table.
A diagnostic routine for a slow workbook
When a model with data tables feels slow, work through these steps in order:
- Set calculation to Automatic except for Data Tables. If the slowness goes away during normal editing, the tables were the cause.
- Press F9 and time the refresh. Count the grid cells across all tables and divide to get the time per recalculation.
- If one recalculation is slow, look for volatile functions, whole-column references, external links and circular references.
- If one recalculation is fast but the total is slow, reduce the grid sizes or merge tables with the same input.
- Paste values for any table you do not need live.
Summary of trade-offs
| Technique | Speed gain | Cost |
|---|---|---|
| Automatic except for Data Tables | Large during editing | Tables can be stale |
| Smaller grids | Proportional to cells removed | Less detail |
| Replace volatile functions | Depends on chain | Formula rewrites need testing |
| Several outputs in one table | Saves whole tables | One-variable tables only |
| Paste values | Removes the cost entirely | Results no longer update |
Exercise
A model takes 0.08 seconds to recalculate. You have one 9 by 9 two-variable table and one one-variable table with 10 input values and 4 output columns. About how long does a full refresh of both tables take, and how could you cut the one-variable table's cost if it was built as four separate tables?
Show answer
The two-variable table has 81 grid cells, so it needs 81 recalculations, or about 6.5 seconds (81 × 0.08 = 6.48). The one-variable table needs 10 recalculations, about 0.8 seconds, because all four output columns share the same recalculation for each input value. Four separate one-variable tables would need 40 recalculations, about 3.2 seconds. Merging them into one table with four output formulas in the top row cuts that cost to 0.8 seconds. The full refresh totals about 7.3 seconds.
Exercise
You set calculation to Automatic except for Data Tables. You change the interest rate in B2 and notice that the check cell =E5-B4 shows 1,247.33 instead of 0. What does this tell you, and what do you do first?
Show answer
The grid is stale. The check cell compares the base case cell in the table with the live model output, and the model has updated while the table has not. Press F9 to refresh the tables, then check that the difference returns to 0. If it still does not, look for other causes, such as axis values that do not include the current inputs, or input cells that do not drive the output.