Calculate XIRR from First Non-Zero to Last Cash Flow in Spreadsheets
Question details
The user needs a single, draggable spreadsheet formula to calculate the XIRR of multiple columns, dynamically identifying the first non-zero value and the last populated value in each cash flow column.

- Product
- Spreadsheets
- Device & OS
- not provided
- Scenario
- Performing financial modeling or investment analysis where initial periods might have zero balances, requiring a flexible formula to accurately measure the internal rate of return without manual range adjustments.
- Observed behavior
- Standard XIRR formulas require manual range selection for each column to avoid errors from leading zeros or blank cells. The user requires an automated approach to define the start and end of the cash flow series.
Ensure your dataset has a dedicated column for valid chronological dates, and that your cash flow columns contain at least one negative value (initial investment) and one positive value (return), as XIRR requires both to compute.
Use a Dynamic Formula with LET and XMATCH
Utilize modern array functions to automatically define the starting point (first non-zero) and endpoint (last populated cell) for the XIRR calculation.
This method creates a dynamic range. By using the LET function to define variables, we can make the formula easier to read. The XMATCH function locates the exact row of the first non-zero value and the final entered value, feeding those precise coordinates into the XIRR function via INDEX.
Click the cell beneath your first cash flow column (e.g., Column B) where you want the XIRR result to appear.
Type the following formula: =LET(cf,B2:B1000,dt,A2:A1000,first,XMATCH(TRUE,cf<>0),last,XMATCH(2,1/(cf<>"")),XIRR(INDEX(cf,first):INDEX(cf,last),INDEX(dt,first):INDEX(dt,last)))
Press Enter. The spreadsheet will dynamically calculate the XIRR ignoring any leading zeros or trailing blank cells.
Click the fill handle at the bottom-right corner of the cell and drag it horizontally across your other cash flow columns to apply the dynamic calculation instantly.

Master Financial Modeling with WPS Spreadsheet
WPS Spreadsheet fully supports advanced financial functions like XIRR, alongside modern dynamic array functions such as LET, XMATCH, and INDEX. This allows you to effortlessly build automated, scalable financial models.
- 1. Open your financial dataset: Launch WPS Spreadsheet and open your cash flow and dates workbook.
- 2. Apply the dynamic formula: Select the result cell and paste the dynamic LET and XMATCH XIRR formula.
- 3. Drag to fill: Use the smart fill handle to drag the formula across all your investment columns for instant results.

Frequently Asked Questions
Why does my XIRR formula return a #NUM! error?
The #NUM! error in XIRR usually means the selected range does not contain at least one negative cash flow (investment) and one positive cash flow (return). It can also occur if the corresponding dates are invalid or not formatted correctly as date values.
Does standard XIRR include zero values in its calculation?
Yes, if zero values are explicitly included in the referenced range, XIRR factors them in as periods with no cash flow. However, skipping leading zeros using dynamic formulas ensures the calculation accurately starts from the initial actual investment date.
Can I use this dynamic formula in older spreadsheet versions?
The LET and XMATCH functions are modern features. If you are using an older version of Excel or WPS Office, you will need to rely on more complex, volatile OFFSET and MATCH array formulas to create dynamic ranges.
What is the difference between XIRR and standard IRR?
Standard IRR assumes all cash flows occur at regular, equal intervals (such as exactly one month or one year apart). XIRR requires specific dates for each cash flow, making it significantly more accurate for real-world investments that have irregular payment schedules.




