Sub topic 6
Building a Two-Variable Data Table
This chapter shows how to build a two-variable data table in Excel. It covers how the row and column input cells map to the grid, a worked loan example, and the errors that most often occur. It assumes you can use absolute and relative references, and that you have a model with hardcoded inputs and one formula-driven output, such as the loan payment model from earlier chapters. You should also have built a one-variable table already.
What a two-variable table does
A one-variable table varies one input and reports one output (or several outputs side by side). A two-variable table varies two inputs at once and reports one output for every pair of values. The result is a grid. Each cell answers a question like "What is the monthly payment if the rate is 7.5% and the term is 20 years?"
The key difference is that a two-variable table can hold only one output formula. It sits in the top-left corner of the table range. The top row holds values for one input, and the left column holds values for the other.
The model
The loan model has three inputs and one output:
B1: 300000 (Loan amount)
B2: 0.065 (Annual interest rate)
B3: 30 (Term in years)
B4: =PMT(B2/12, B3*12, -B1) (Monthly payment, the output)The output in B4 depends on B1, B2 and B3. That dependency is what makes a data table work. The table does not read any cell in the grid for its logic. It temporarily writes each pair of values into the input cells, lets the model recalculate, and records the value of the output formula.
Layout of the table
Place the table next to the model on the same sheet. The layout looks like this:
| Row | E | F | G | H | I |
|---|---|---|---|---|---|
| Row 2 | 10 | 15 | 20 | 25 | 30 |
| Row 3 | result | result | result | result | result |
In full, the range is D2:I7:
- D2 holds the output formula
=B4. - E2:I2 hold the term values: 10, 15, 20, 25, 30.
- D3:D7 hold the rate values: 4.5%, 5.5%, 6.5%, 7.5%, 8.5%.
- E3:I7 is the result area, which Excel fills in.
Enter the headers as plain numbers, not formulas that depend on the model's inputs. If the axis values link to B2 or B3, they change while the table runs, and the results become wrong.
D2: =B4
E2:I2 (years): 10, 15, 20, 25, 30
D3:D7 (rates): 0.045, 0.055, 0.065, 0.075, 0.085
Select D2:I7 > Data > What-If Analysis > Data Table
Row input cell: B3 (term, matches the values across the top)
Column input cell: B2 (rate, matches the values down the side)
Result in E3:I7: {=TABLE(B3,B2)}Choosing the row and column input cells
The dialog has two boxes, and the names are the most common source of mistakes.
- The row input cell is the input that the values in the top row replace.
- The column input cell is the input that the values in the left column replace.
Here the top row holds years, so the row input cell is B3 (the term). The left column holds rates, so the column input cell is B2 (the rate).
A reliable way to remember this: name the box after where the values sit, not after where the results go. Values across a row go in the "Row input cell" box.
Building it step by step
- Confirm that B4 depends on B2 and B3 through formulas, and that B2 and B3 contain typed values, not formulas.
- Type
=B4in D2. - Type the five term values in E2:I2.
- Type the five rate values in D3:D7, formatted as percentages.
- Select D2:I7. Include the corner cell and both header strips.
- Open Data > What-If Analysis > Data Table.
- Enter B3 as the row input cell and B2 as the column input cell.
- Click OK.
Excel fills E3:I7. Click any result cell and you will see {=TABLE(B3,B2)} in the formula bar. The braces show that it is an array formula that you cannot edit by hand. The first argument is the row input cell and the second is the column input cell. If you see {=TABLE(,B2)}, you built a one-variable column table instead.
Reading the result
Monthly payments fall as the term gets longer and rise as the rate gets higher. Along a row, the payment drops quickly from 10 to 15 years and then levels off. Down a column, the payment grows steadily with the rate. These patterns are the real product of the table. You are looking for the shape of the sensitivity, such as which input moves the output more and where the effect flattens.
Check the base case
A table can look plausible and still be wrong, for example when the axes are swapped. Always compare one grid cell to the live model. The current inputs are 6.5% and 30 years, so the matching cell is E5 in the 6.5% row... except that 30 years is in column I. Use the cell where both headers match the current inputs, which is I5.
If your layout puts the base case in a different cell, adjust the reference. The check formula in the sample layout is:
K2: =E5-B4This formula assumes the base case sits at E5. For the layout in this chapter, point it at the real base-case cell instead:
K2: =I5-B4The result should be exactly 0. If it is not, one of these is true:
- The input cells are reversed in the dialog.
- The axis values are not exactly the same as the model's inputs. For example, 0.065 typed as 6.5 gives a wildly different result.
- Calculation is set to Automatic except for Data Tables and the table is stale.
Because the table recalculates the whole model, even small differences in the headers show up as a non-zero check.
Highlighting the base case
A conditional formatting rule can mark the cell whose headers match the current inputs. Select E3:I7 and add a formula rule:
Conditional formatting rule applied to E3:I7:
=AND($D3=$B$2, E$2=$B$3)The mixed references matter. $D3 locks the column and lets the row move, so each cell compares its own row's rate to B2. E$2 locks the row and lets the column move, so each cell compares its own column's term to B3. If you change B2 to 7.5%, the highlight moves to the 7.5% row on its own.
A color scale on the same range makes the pattern visible at a glance. Apply it separately from the base-case rule so that the highlight stays distinct.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Every cell shows the same number | The input cells are not referenced by the output formula, or they are on another sheet | Move the table to the same sheet as the inputs and confirm the dependency |
| Grid looks mirrored or wrong | Row and column input cells swapped | Rebuild the table with the swapped cells |
| Base case check is not 0 | Headers do not match the inputs, or the table is stale | Fix the header values and press F9 |
| Results never change | Calculation mode excludes data tables | Press F9, or switch to Automatic |
| "Input cell reference is not valid" | The input cell is on a different sheet | Link a same-sheet input to the other sheet's model, or move the table |
| Can't change part of a table | Table cells are one array | Clear all of E3:I7 and rebuild |
The same-sheet rule
Both input cells must be on the same sheet as the table. If your model is on another sheet, place the input cells on the table's sheet and have the model refer to them. The data table writes values into those cells, so the model must read from them.
Inputs must be values
If B2 is a formula, such as =Assumptions!C5, the table overwrites it only temporarily during calculation, but any chain that bypasses B2 will ignore the substitution. Keep each input cell as a hardcoded value that the model reads.
Calculation behavior
Data tables recalculate every time the workbook does, and each grid cell needs a full model recalculation. This table has 25 cells, which is trivial. A table of 50 by 50 cells on a large model forces 2,500 recalculations per refresh.
Under Formulas > Calculation Options, Automatic except for Data Tables recalculates everything except tables. Press F9 to update them. Use this setting on heavy models, and always press F9 before reading the table or copying numbers out of it.
Exercise
Exercise
You build a two-variable table with rates down the left column in D3:D7 and terms across the top in E2:I2. The model inputs are B2 (rate) and B3 (term). In the Data Table dialog you enter B2 as the row input cell and B3 as the column input cell. What goes wrong, and what does the formula bar show for the result cells?
Show answer
The inputs are swapped. Excel substitutes the term values (10 to 30) into the rate cell B2, and the rate values (0.045 to 0.085) into the term cell B3. Rates of 10 to 30 mean 1000% to 3000% per year, and terms near 0.05 years give nonsense payments. The formula bar shows {=TABLE(B2,B3)} instead of the correct {=TABLE(B3,B2)}. The base-case check fails. Rebuild the table with B3 as the row input cell and B2 as the column input cell.
Exercise
Your table's base-case cell is I5 and the check cell K2 contains =I5-B4. It shows 0.00 until you change the loan amount in B1 from 300000 to 350000, then it shows a large non-zero number. The table was working before. What is the most likely cause, and how do you confirm it?
Show answer
The calculation mode is probably Automatic except for Data Tables, so the table did not recalculate after B1 changed. Press F9. If K2 returns to 0, the table was stale. You can confirm the mode under Formulas > Calculation Options.