Sub topic 6
MIN and MAX Basics
This chapter covers what MIN and MAX return, how they treat blanks, text and errors, and why a floor uses MAX and a cap uses MIN. It assumes you can copy formulas across a row, anchor references with $, and read a forecast with periods in columns. Later chapters use these functions for tax and debt repayment, so the basics need to be solid first.
What the functions do
MAX returns the largest of its arguments. MIN returns the smallest.
=MAX(F10,F11)
=MIN(F10,F11)Each function accepts up to 255 arguments. An argument can be a number, a cell reference, a range, or a formula result.
=MAX(0,F30)
=MIN(F20*$C$3,$C$4)
=MAX(F10:K10)The first formula compares a constant with a cell. The second compares a calculation with an input cell. The third scans a range and returns the largest value in it.
The two kinds of argument work differently, and mixing them up is a common source of mistakes:
- Separate arguments, as in
MAX(F10,F11), compare cells that belong to the same period. Copied across the row, each column compares its own two cells. - A range, as in
MAX(F10:K10), collapses many cells into one answer. Use it for a peak or a trough across time, such as the lowest cash balance in the forecast.
Why the names look backwards
In a model, MAX and MIN are mostly used as limits, and the names seem to point the wrong way.
MAX(0, x)sets a floor. The result is never below zero.MIN(x, cap)sets a cap. The result is never above the cap.
The reason is that MAX picks the larger value, so the result can only be as small as the floor you supply. MIN picks the smaller value, so the result can only be as large as the cap you supply.
The diagram shows a value passing through a floor and then a cap.
A worked example
Take four values for a line item and apply a floor of 0 and a cap of 100.
| Value x | `MAX(0,x)` | `MIN(x,100)` | `MIN(MAX(x,0),100)` |
|---|---|---|---|
| -50 | 0 | -50 | 0 |
| 0 | 0 | 0 | 0 |
| 120 | 120 | 100 | 100 |
| 400 | 400 | 100 | 100 |
The MAX column changes only the negative value. The MIN column changes only the large values. The last column combines both limits and keeps every result between 0 and 100.
Now a realistic cap. A bonus is a percentage of a base amount, but it cannot exceed a maximum. The inputs are:
| Cell | Meaning | Value |
|---|---|---|
| C3 | Bonus rate | 10% |
| C4 | Maximum bonus | 5,000 |
| F20 | Base amount in the period | 80,000 |
=MIN(F20*$C$3,$C$4)The calculation gives 80,000 × 10% = 8,000. MIN(8000, 5000) returns 5,000. If the base is 30,000, the calculation gives 3,000, and MIN(3000, 5000) returns 3,000, because the cap is not reached.
The two limits are inputs in C3 and C4, not numbers typed into the formula. If the rate changes, you edit one cell and every period updates.
Limits can be calculated
A floor or cap does not have to be a constant or an input. It can be another cell or a formula. The debt repayment formula from this tutorial relies on this:
=MIN(F41,MAX(0,F38))Read it from the inside out:
MAX(0,F38)takes the cash available in F38 and ignores a shortfall, so the amount is never negative.MIN(F41, ...)compares that amount with the opening debt balance in F41, so the repayment never exceeds what is owed.
Here the cap (F41) changes every period because the debt balance changes. The formula is still one consistent expression across the row. Chapter details on the debt sweep come later. At this point, notice that nesting lets one formula respect two limits at once.
How MIN and MAX treat unusual cells
Most formula errors with these functions come from cells that are not plain numbers. The rules below apply to Excel. Google Sheets behaves the same way in the cases listed.
| Cell contents | Reached through a reference or range | What happens |
|---|---|---|
| Number | Yes | Used in the comparison |
| Blank | Yes | Ignored |
| Text, such as "n/a" | Yes | Ignored |
| `TRUE` or `FALSE` | Yes | Ignored |
| Error, such as `#DIV/0!` | Yes | The error is returned |
| No numbers at all | Yes | Returns 0 |
Three of these deserve attention.
Blanks are not zeros. Suppose F41 is the opening debt balance and the cell is empty because a link is broken. MIN(F41, MAX(0,F38)) ignores F41 and returns the cash amount, so the model repays debt that does not exist. A cell that holds an actual 0 is compared, and the formula correctly returns 0. If a blank would be a mistake, make the model show it, for example by checking that the balance row is fully populated.
Text is skipped without warning. A label or a pasted "n/a" in the middle of a row disappears from MAX(F10:K10). The result is a number, and nothing signals that a cell was left out. Text produced by a formula, including an empty string "", is skipped the same way.
Errors spread. One #REF! anywhere in the compared cells makes the whole result #REF!. This is usually what you want, because it shows a broken link. Do not hide it with IFERROR around the limit formula, which would let a wrong number flow into later periods.
If you need text treated as 0 and TRUE as 1, use MAXA and MINA. They are rarely right in a model, because the conversion hides data problems.
Sign conventions change which function you need
Many models show costs, tax and repayments as negative numbers. The logic of floors and caps then reverses.
Suppose expenses are entered as negatives and must never be positive. "Never above zero" is a cap, so the formula is MIN(0, x). A positive cost would be forced to 0.
To avoid confusion, decide on a sign convention for the whole model and write it next to the inputs. For a given formula, translate the requirement into plain words and then choose the function. The words "at least" call for MAX, and "at most" calls for MIN.
| Requirement | Function | Example |
|---|---|---|
| Result at least 0 | `MAX` | `=MAX(0,F30)` |
| Result at most the cap in C4 | `MIN` | `=MIN(F20,$C$4)` |
| Negative amount no larger than 0 | `MIN` | `=MIN(0,F25)` |
| Smaller of two balances | `MIN` | `=MIN(F41,F38)` |
Clamping with both limits
When a value must stay inside a range, nest the two functions:
=MIN(MAX(F20,$C$3),$C$4)Here C3 is the lower limit and C4 is the upper limit. The inner MAX applies the floor and the outer MIN applies the cap.
If the limits are entered the wrong way round, so the lower limit is larger than the upper limit, the order of nesting decides the answer:
MIN(MAX(x, low), high)returnshigh.MAX(MIN(x, high), low)returnslow.
Neither result is a sensible figure, and both look like valid numbers. If the limits come from user inputs, add a check cell that confirms the lower limit does not exceed the upper limit.
Small differences and rounding
Calculations that should land exactly on a limit sometimes miss it by a tiny amount, such as 0.0000000001, because of floating point arithmetic. A floor such as MAX(0, x) then returns that tiny positive number instead of 0. The effect is usually harmless, but a later flag that tests whether the result is greater than 0 will treat it as positive. If this matters, round the value that feeds the floor, for example with ROUND(F38, 2).
A short review routine
Before you rely on a formula that uses MIN or MAX, check the following:
- State in words what the formula must guarantee, such as "never negative" or "never above the balance".
- Confirm the function matches the words:
MAXfor "at least",MINfor "at most". - Confirm the limits are in input cells or come from named rows. They should not be typed into the formula.
- Check the sign convention for every row involved.
- Test an extreme value on each side, such as a large loss and a very large gain, and see whether the result stops at the limit.
- Look for blank or text cells in the referenced rows.
Exercise
A bonus is 10% of the base amount in F20, stored in rate cell C3, and cannot exceed the maximum in C4. The base amount is 80,000 and C4 is 5,000. Write the formula, give the result, and say what it returns if C4 is accidentally left blank.
Show answer
The formula is =MIN(F20*$C$3,$C$4). The calculation gives 8,000, and MIN with the 5,000 cap returns 5,000. If C4 is blank, MIN ignores that blank cell and returns 8,000, so the cap silently stops working. The model should check that the input is filled in.
Exercise
Cash available is in F38 and may be negative. The opening debt balance is in F41. Write a formula for the repayment that is never negative and never more than the balance. Then calculate the result for cash of -200 with a balance of 1,000, and for cash of 1,500 with a balance of 1,000.
Show answer
Use =MIN(F41,MAX(0,F38)). For cash of -200, MAX(0,-200) is 0, and MIN(1000,0) is 0, so no repayment. For cash of 1,500, MAX(0,1500) is 1,500, and MIN(1000,1500) is 1,000, so the repayment is limited to the balance.
Exercise
Costs are entered as negative numbers. A formula in F25 must make sure a cost is never positive. Which function and formula should you use, and why would MAX(0,F25) be wrong?
Show answer
Use =MIN(0,F25). A cost that must be "at most 0" needs a cap at 0, so MIN is correct. MAX(0,F25) would turn every negative cost into 0 and remove the costs from the model.