Sub topic 11
Fixing #NUM!: invalid numeric results
This chapter assumes you can enter and edit formulas, use cell references and ranges, and know the difference between numbers and text in cells. It also assumes you have read the earlier chapters on #DIV/0! and #VALUE!, so the general idea of an error value is not repeated here.
What #NUM! means
Excel returns #NUM! when a formula is valid in form and its arguments are numbers, but the math cannot produce a usable result. The problem is the number, not the type of the input. That separates it from #VALUE!, where an argument has the wrong type, such as text where a number is needed.
There are three common causes:
- The function is given a number outside the range where it is defined, such as the square root of a negative number.
- The result is too large or too small for Excel to store.
- An iterative function, such as IRR or RATE, cannot find an answer within its allowed number of tries.
Excel stores numbers as 64-bit floating-point values. The largest magnitude is about 1.8E+308 and the smallest nonzero magnitude is about 2.2E-308. Typing a literal outside this range, or computing one, gives #NUM!.
| Cause | Example | Result |
|---|---|---|
| Negative input to a root | `=SQRT(-4)` | #NUM! |
| Logarithm of zero or a negative number | `=LN(0)` | #NUM! |
| Result too large | `=10^400` | #NUM! |
| Argument outside the allowed range | `=SMALL(A1:A5,10)` when the range has 5 numbers | #NUM! |
| Iteration does not converge | `=IRR(A1:A4)` with all positive cash flows | #NUM! |
Diagnosing the cause
Work through three questions in order.
- Does the formula use a function with a restricted domain? Check SQRT, LN, LOG, LOG10, FACT, and the statistical functions.
- Could the result be extremely large? Look for exponents, FACT, COMBIN, or a formula that multiplies a long chain of values.
- Is the function iterative? IRR, XIRR, RATE, and YIELD search for an answer by trial and error.
Evaluate Formula, covered in an earlier chapter, is the quickest way to see which part of a long formula returns #NUM! first.
Invalid arguments to math functions
Some functions are defined only for part of the number line.
- SQRT needs a value of zero or more.
- LN, LOG, and LOG10 need a value greater than zero.
- FACT needs a value of zero or more.
- A negative number raised to a fractional power, such as
=(-8)^(1/3), returns #NUM!.
Excel does not return a complex number, and it does not take the real cube root for you. If you need a real cube root of a negative number, handle the sign yourself:
=SIGN(A2)*ABS(A2)^(1/3)For SQRT, guard the call so that it runs only on valid input:
=IF(A2>=0,SQRT(A2),"")This formula returns an empty string for a negative value. That is a choice you make about what the cell should show. Sometimes a visible message is better, for example "Negative input", so that a reader knows why the cell is empty.
A related case is a negative value that comes from your data and should not be there. If A2 holds a measured length and a typo made it negative, the guard hides the symptom. Fixing the source cell is the real repair. The last chapter in this tutorial covers that trade-off in detail.
Functions that return #NUM! for out-of-range positions
Functions that pick the nth value from a set return #NUM! when n is larger than the count of values. SMALL, LARGE, and PERCENTILE behave this way. For example:
=LARGE(A1:A5,6)The range holds at most five numbers, so asking for the sixth largest fails. Blank cells and text do not count as numbers. If your range has five rows but only three contain numbers, LARGE(A1:A5,4) also fails. Compare the position you ask for with COUNT(A1:A5):
=IF(B1<=COUNT(A1:A5),LARGE(A1:A5,B1),"Not enough values")Results too large or too small
Excel stops at roughly 1.8E+308. The following formulas exceed that limit:
=10^309
=FACT(171)FACT(170) works and gives about 7.26E+306. FACT(171) overflows. If you need very large factorials for something like probability, work with logarithms instead. FACTDOUBLE and COMBIN have similar limits, and COMBIN returns #NUM! when the number of items is smaller than the number chosen.
Repeated growth is another source. A formula that compounds a rate over many periods can overflow when the period count is entered wrongly. A rate of 5% for 36 periods is normal. A rate typed as 5 instead of 0.05 is 500%, and compounding it across thousands of periods overflows. When #NUM! appears in a growth model, check that rates are stored as fractions or formatted as percentages, and that period counts are plausible.
Very small results behave differently. Excel does not always return #NUM! when a value is too small. Results near the smallest representable size usually become zero. A later division by that zero then gives #DIV/0!, so the visible error may be a different one than the one that caused the trouble.
Iterative functions that fail to converge
IRR, XIRR, RATE, and YIELD do not use a closed formula. Excel starts from a guess and improves it repeatedly. For IRR and RATE, the search stops after 20 tries. If it has not settled on an answer by then, the function returns #NUM!.
Convergence also fails when no answer exists. IRR needs at least one positive and at least one negative value in the cash flows. A list of only inflows has no internal rate of return.
=IRR(B2:B8)Suppose B2:B8 holds an initial outflow of -10000 followed by six inflows. This works. If the outflow cell is blank, or is stored as text and therefore ignored, only positive values remain and IRR returns #NUM!.
To repair an iterative function:
- Confirm the cash flows include both signs. Check for numbers stored as text, which IRR ignores in a range.
- Supply a guess closer to the likely answer. The second argument of IRR is the guess:
=IRR(B2:B8,0.05)- Try a different guess, such as a negative one like -0.1, when the investment loses money.
- For irregular dates, use XIRR, which takes dates as well as values. XIRR also needs at least one positive and one negative value.
Note that a different guess can lead to a different answer when the cash flows change sign more than once. Such cash flows can have several valid rates of return, and Excel reports only the one it finds first.
Invalid numbers typed into arguments
Some arguments must fall within a fixed interval. Excel returns #NUM! when a value falls outside it, even though the formula is otherwise well formed.
| Function | Rule | Failing example |
|---|---|---|
| PERCENTILE | k must be between 0 and 1 | `=PERCENTILE(A1:A10,1.5)` |
| NORM.S.INV | probability must be between 0 and 1, not including either end | `=NORM.S.INV(1)` |
| DATE-based arithmetic | the resulting date must be valid | `=DATE(10000,1,1)` |
| ROUND-like digit arguments | the number of digits is accepted widely, so they rarely fail | not a common cause |
A frequent mistake is passing a percent value as a whole number. A user who types 95 meaning 95% into a percentile argument gets #NUM!, because the function expects 0.95. Format the input cell as a percentage or divide by 100.
Dates are another case. Excel's date system has a limit at the year 9999, and negative serial numbers are not valid dates in the 1900 system. A subtraction that goes before the start of the calendar can display ##### in a date-formatted cell instead of #NUM!. Functions that take a date argument, such as EDATE, return #NUM! when the result would fall outside the supported range.
Handling #NUM! on purpose
Use IF to prevent the error when you know the condition that causes it. Use IFERROR only when you accept any failure in that formula as equivalent.
=IFERROR(IRR(B2:B8),"No IRR")This formula shows "No IRR" when IRR cannot find a rate. That is reasonable in a report where some projects have no valid rate. The same wrapper would also hide a typo in the range or a #VALUE! from a bad input, because IFERROR catches every error type. When you want to treat only invalid math as expected, test the condition directly:
=IF(AND(COUNTIF(B2:B8,">0")>0,COUNTIF(B2:B8,"<0")>0),IRR(B2:B8),"Needs both inflows and outflows")The check passes only when the range contains at least one positive and one negative number. A real error in IRR itself then still shows.
Summary of fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| `=SQRT(A2)` gives #NUM! | A2 is negative | Correct the data or use `IF(A2>=0,SQRT(A2),"")` |
| `=LN(A2)` gives #NUM! | A2 is zero or negative | Check that A2 is greater than zero |
| `=LARGE(A1:A5,n)` gives #NUM! | n exceeds the count of numbers | Compare n with COUNT |
| Growth formula gives #NUM! | Overflow from a wrong rate or period count | Check that rates are fractions |
| `=IRR(...)` gives #NUM! | No sign change, or no convergence | Check both signs and supply a guess |
| Statistical function gives #NUM! | Argument outside its interval | Rescale the input, for example to 0.95 |
Exercise
Cell B2 holds the cash flows -5000, 1200, 1800 and 2600 in B2:B5 and the formula =IRR(B2:B5) works. A colleague pastes the values again and the outflow in B2 becomes the text "-5000". The formula now returns #NUM!. Explain why, and write a formula that shows "Needs both inflows and outflows" when the range lacks a negative number or a positive number.
Show answer
IRR ignores text in a range, so the text "-5000" is dropped and only positive values remain. With no sign change, IRR has no solution and returns #NUM!. Convert the text to a number first, for example with =VALUE(TRIM(B2)) or by retyping it. A guard formula is =IF(AND(COUNTIF(B2:B5,">0")>0,COUNTIF(B2:B5,"<0")>0),IRR(B2:B5),"Needs both inflows and outflows"). COUNTIF with a numeric criterion counts only real numbers, so a text "-5000" does not satisfy "<0" and the guard shows the message.
Exercise
A cell contains =LARGE(A1:A10,C1). A1:A10 holds 6 numbers and 4 blank cells, and C1 contains 8. What does the formula return, and how can you prevent the error while still showing a clear message?
Show answer
It returns #NUM!, because LARGE counts only numbers and the range has 6, so the 8th largest does not exist. Use =IF(C1<=COUNT(A1:A10),LARGE(A1:A10,C1),"Not enough values"). This prevents the error only for this specific cause, so other problems, such as a bad range, still show.