How to use the XNPV function
What is the XNPV function?
The XNPV function calculates the net present value for cash flows that may or may not be periodic. Net present value is used in investment planning and capital budgeting.
Table of Contents
1. Introduction
What is net present value?
Net present value (NPV) is a core concept in finance where the present value of an investment's future cash inflows is calculated and compared to the initial outlay to see if the investment is profitable over time.
What is cash flow?
A cash flow is the net amount of cash moving into or out of a business during a given time period, representing inflows from revenue and outflows for expenses, investments, financing, and dividends.
What is periodic cash flow?
Periodic cash flow is a regular cash inflow or outflow occurring at fixed intervals over time, like an annuity, loan payment, or payroll.
What is non-periodic cash flow?
Non-periodic cash flow is a cash inflow or outflow that occurs at irregular intervals and does not follow a precise schedule, like inventory purchases or one-time dividends.
XNPV related functions in Excel
Function | Description |
---|---|
XNPV(rate, values, dates) | Returns net present value for irregular cash flows |
NPV(rate, value1, value2...) | Returns net present value for regular cash flows |
IRR(values, guess) | Returns internal rate of return for cash flows |
PMT(rate, periods, present value, [future value], [type]) | Returns periodic payment amount |
FV(rate, periods, payment, [present value], [type]) | Returns future value of cash flows |
CUMIPMT(rate, nper, pv, start_period, end_period, type) | Calculates cumulative interest payments. |
DISC(settlement, maturity, pr, redemption, [basis]) | Calculates discount rate or bond equivalent yield |
How is the XNPV Function calculated?
The formula looks like this:
di = the ith, or last, payment date.
d1 = the 0th payment date.
Pi = the ith, or last, payment.
The text representation of the formula shown in the image is:
XNPV = Σ(i=1 to N) [Pi / (1 + rate)^((di - d1)/365)]
N is the total number of payments.
Pi is the ith (or last) payment.
rate is the discount rate.
di is the ith (or last) payment date.
d1 is the 0th payment date.
2. Syntax
XNPV(rate, values, dates)
rate | Required. The discount rate. |
values | Required. A number of values representing cash flow, the first value is optional and may be a cost or payment. Make sure the first value is a negative value if it is a cost or payment. At least one value must be negative and one value must be positive. |
dates | Required. Dates that correspond to the cash flow values. |
What is a discount rate?
The discount rate is the interest rate used to calculate the present value of future cash flows. It accounts for the time value of money - money today is worth more than money in the future. Higher discount rates result in lower net present values.
3. Example 1
You are considering an investment opportunity that will generate the following irregular cash flows:
Cash flows | Dates |
$10,000 | 1/1/2026 |
$12,000 | 6/1/2026 |
$15,000 | 1/1/2028 |
$18,000 | 1/1/2029 |
$20,000 | 1/1/2030 |
If the required rate of return is 8%, what is the XNPV of this investment?
Arguments: XNPV(rate, values, dates)
- rate: 8% (required rate of return)
- values: An array containing the cash flows
(10,000, 12,000, 15,000, 18,000, 20,000) - dates: An array containing the dates corresponding to each cash flow
(e.g., 1/1/2026, 6/1/2026, 1/1/2028, 1/1/2029, 1/1/2030)
Formula in cell C26:
The formula in cell C26 returns $63,467.50 which represents the net present value of the given irregular cash flows.
The image above the shows a chart displaying blue columns representing cash flows amounts. The data labels above each column shows the actual cash flow amount. The x-axis shows the dates and the y-axis the amount in $ (dollars).
The text representation of the math formula is:
XNPV = Σ(i=1 to N) [Pi / (1 + rate)^((di - d1)/365)]
Cash flow 1:
P1 = $10,000
d1 = 1/1/2026 (0th payment date)
PV1 = $10,000 / (1 + 0.08)^((1/1/2026 - 1/1/2026)/365) = $10,000
Cash flow 2:
P2 = $12,000
d2 = 6/1/2026
PV2 = $12,000 / (1 + 0.08)^((6/1/2026 - 1/1/2026)/365)
PV2 = $12,000 / (1 + 0.08)^(151/365) = $11,623.95
Cash flow 3:
P3 = $15,000
d3 = 1/1/2028
PV3 = $15,000 / (1 + 0.08)^(730/365) = $12,860.08
Cash flow 4:
P4 = $18,000
d4 = 1/1/2029
PV4 = $18,000 / (1 + 0.08)^(1096/365) = $14,285.97
Cash flow 5:
P5 = $20,000 d5 = 1/1/2030
PV5 = $20,000 / (1 + 0.08)^(1461)/365) = $14,697.50
Sum the present values of all cash flows to obtain the XNPV.
XNPV = PV1 + PV2 + PV3 + PV4 + PV5
XNPV = $10,000 + $11,623.95 +$12,860.08 + $14,285.97 + $14,697.50
XNPV = $63,467.50
This value matches the calculated value in cell C26.
4. Example 2
You are considering two investment alternatives, A and B. Alternative A generates cash flows of $10,000, $12,000, and $15,000 over the next 3 years, while Alternative B generates cash flows of $8,000, $14,000, and $18,000 over the same period. If the required rate of return is 9%, which alternative has a higher NPV?
Here are the arguments for alternative A:
rate: 9% (required rate of return)
values: An array containing the cash flows for alternative A: [10000, 12000, 15000])
dates: An array containing the dates corresponding to each cash flow for alternative A: [1/1/2025, 1/1/2026, 1/1/2027]
Here are the arguments for alternative B:
rate: 9% (required rate of return)
values: An array containing the cash flows for alternative B: [8000, 14000, 18000])
dates: An array containing the dates corresponding to each cash flow for alternative B: [1/1/2025, 1/1/2026, 1/1/2027])
Formula in cell C25:
The formula in cell C25 returns $35,341.19 which represents the net present value of the given irregular cash flows for alternative A.
Formula in cell F25:
The formula in cell F25 returns $36,779.43 which represents the net present value of the given irregular cash flows for alternative B.
The image displays a chart titled "XNPV function" and two data tables comparing two investment alternatives, Alternative A and Alternative B, using the XNPV (Net Present Value) function in Excel. The chart shows the cash flows for both alternatives A and B over time, represented by vertical bars with colors blue and red respectively.
Based on the XNPV values in cells C25 and F25, alternative B has a higher net present value of $36,779.43 compared to alternative A's $35,341.19, suggesting that alternative B may be the more profitable investment opportunity when considering the irregular cash flow schedules and the specified discount rate of 9%.
5. Why is the function not working?
The XNPV function returns:
- #VALUE! error if arguments are non-numeric.
- #NUM! error if any number in dates precedes the starting date.
- #NUM! error if values and dates don't have the same number of values.
- #VALUE! error if any number in dates is not a valid date.
5.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
5.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B5:B10 converted to hard-coded value using the F9 key. The XNPV function requires numerical values in the second argument which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
5.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Functions in 'Financial' category
The XNPV function function is one of 27 functions in the 'Financial' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form