XIRR with non-contiguous data

rwilson200

New Member
Joined
Mar 15, 2018
Messages
3
Although there have been helpful discussions about Excel 2013's XIRR function using non-contiguous cells, I can't get any suggestions to work in my particular situation. Below is an excerpt from a large spreadsheet covering a number of years. It shows some formulas that work and some that don't, along with columns used for showing correct XIRRs for various time periods.

I would like to calculate XIRR for rolling YTD, 12 month, and 36 month periods. For example, for the 12 month period ending 3/31/17, I would like to use the starting value in cell C4, the cashflow range B5:B15, and the ending value -C16 (note the negative). For the next new month, I insert a row above row 16, copy the 3/31/17 data to the newly inserted row, then add new data for 4/30/17.

XIRR can't handle multiple ranges but I found a workaround that can deal with input from two non-contiguous ranges. However, this workaround can't handle three ranges or make C16 negative. Furthermore, I'm puzzled how the multiple ranges seem work in the XIRR formula shown in C24.

IRR could be annualized to get the return I'm looking for and it works with multiple ranges if they are assigned a range name. So, I could use an assigned name (e.g. =IRR(cashflow)), but the ranges vary monthly and the ending value must be made negative. I don't know how to deal with these variables.

Some of my attempts used OFFSET to select the last 12 months of data, but I'm still stuck on trying to pick the three ranges that I need. I imagine the solution will involve CHOOSE but I can't seem to figure out how to make it work.

A couple preferences: 1) the extent of the spreadsheet prevents me from using nearby cells for placeholders/work areas and 2) I would prefer to avoid VBA is possible.

GoogleSheets appears to handle multiple ranges perfectly, even changing some of them negative inside the formula, but using GoogleSheets isn't possible in my situation.

Any suggestions will be greatly appreciated.

Excel 2013 32 bit

[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]A[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]B[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]C[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]D[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]E[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]F[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]G[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]H[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]1[/COLOR]​
Month
ending

monthly cashflow
deposits (+) withdrawals (-)

ending
balance

monthly
return
overall
cashflow

12 month
cashflow

[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]2[/COLOR]​
1/31/16
84,620
84,620
84,620
-84,620​
-84,620
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]3[/COLOR]​
2/28/16
0
84,460
-0.2%​
0​
0​
0​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]4[/COLOR]​
3/31/16
0
85,800
1.6%​
0​
85,800
0​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]5[/COLOR]​
4/30/16
-5,500
90,720
12.1%​
-5,500​
-5,500​
-5,500​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]6[/COLOR]​
5/31/16
0
93,500
3.1%​
0​
0​
0​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]7[/COLOR]​
6/30/16
9,000
84,990
-18.7%​
9,000​
9,000​
9,000​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]8[/COLOR]​
7/31/16
-1,000
86,070
2.4%​
-1,000​
-1,000​
-1,000​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]9[/COLOR]​
8/31/16
-2,700
87,510
4.8%​
-2,700​
-2,700​
-2,700​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]10[/COLOR]​
9/30/16
0
89,930
2.8%​
0​
0​
0​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]11[/COLOR]​
10/31/16
0
87,530
-2.7%​
0​
0​
0​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]12[/COLOR]​
11/30/16
0
87,640
0.1%​
0​
0​
0​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]13[/COLOR]​
12/31/16
0
92,850
5.9%​
0​
0​
0​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]14[/COLOR]​
1/31/17
300
94,980
2.0%​
300​
300​
94,980
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]15[/COLOR]​
2/28/17
300
96,510
1.3%​
300​
300​
300​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]16[/COLOR]​
3/31/17
300
94,030
-2.9%​
-94,030
-94,030
-94,030
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]17[/COLOR]​
these work:source data is in red above and aren't to be changed
Columns F-H aren't part of original spreadsheet and are for showing correct XIRRs.
Data in purple has been changed from source at left to calculate XIRR for the period.

[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]18[/COLOR]​
12 mo annualized TWR (4/1/16 - 3/31/17):​
7.357%​
{=PRODUCT(1+OFFSET(D16,-11,0, 12, 1))-1}
9.121%​
9.176%​
-7.856%
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]19[/COLOR]​
12 mo annualized TWR (4/1/16 - 3/31/17):​
7.357%​
{=PRODUCT(1+D5:D16)-1}
=XIRR(F2:F16,$A$2:A16)​
=XIRR(G4:G16,A4:A16)​
=XIRR(H14:H16,A14:A16)​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]20[/COLOR]​
YTD TWR (1/1/17 - 3/31/17):​
0.316%​
{=PRODUCT(1+OFFSET(D16,-MONTH($A$16)+1,0,MONTH($A$16)))-1}
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]21[/COLOR]​
YTD TWR (1/1/17 - 3/31/17):​
0.316%​
{=PRODUCT(1+D14:D16)-1}
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]22[/COLOR]​
12 mo IRR (4/1/16 - 3/31/17):​
0.734%​
=IRR(cashflow1)
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]23[/COLOR]​
Annualized IRR:​
9.177%​
=((1+B22)^12)-1
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]24[/COLOR]​
XIRR for entire history:​
9.121%​
{=XIRR(IF(ROW($2:16)< ROW(A16),$B$2:B15,-C16), A2:A16)}
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]25[/COLOR]​
in above formula, for rows 2-15, XIRR uses values in C2:C15, but for row 16, how does XIRR use D16?
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]26[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]27[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]28[/COLOR]​
these don't work:
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]29[/COLOR]​
12 mo XIRR (4/1/16 - 3/31/17):​
0.000000298%​
{=XIRR(OFFSET(B16,-12,0,13),OFFSET(A16,-12,0,13),0.1)}
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]30[/COLOR]​
12 mo XIRR (4/1/16 - 3/31/17):​
#NUM!​
=IRR(cashflow2)
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]31[/COLOR]​
Annualized IRR:​
#NUM!​
=((1+B30)^12)-1
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]32[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]33[/COLOR]​
YTD XIRR (1/1/17 - 3/31/17):​
#VALUE!​
{=XIRR(($B$14:B15,C16), A14:A16)}
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]34[/COLOR]​
YTD XIRR (1/1/17 - 3/31/17):​
#NUM!​
{=XIRR(OFFSET(B16,-MONTH($A$16)+1,0,MONTH($A$16)),OFFSET(A16,-MONTH($A$16)+1,0,MONTH($A$16)))}
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]35[/COLOR]​
YTD XIRR (1/1/17 - 3/31/17):​
1.84901E+15​
{=XIRR(IF(ROW(OFFSET(B16,-MONTH($A$16)+1,0,MONTH($A$16),1))< ROW(A16),OFFSET(B16,-MONTH($A$16)+1,0,MONTH($A$16), 1),-C16),OFFSET(A16,-MONTH($A$16)+1,0,MONTH($A$16),1))}
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]36[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]37[/COLOR]​
IRR for entire history (1/31/16 - 3/31/17):​
#VALUE!​
=IRR((B2:B15),-C16)
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]38[/COLOR]​
Annualized IRR:​
#VALUE!​
=((1+B37)^12)-1

<tbody>
</tbody>
Sheet: worksheet

<tbody>
</tbody>
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Welcome to the Forum!

Perhaps something like this:

B37 (for example): =XIRR(B21:B33,A21:A33)

Period: =B41

C44: =XIRR(IF(ROW(INDIRECT(B44-Period & ":" & B44))=B44-Period,INDEX(MyData,B44-Period,3),INDEX(MyData,B44-Period,2):INDEX(MyData,B44,2)-IF(ROW(INDIRECT(B44-Period & ":" & B44))=B44,INDEX(MyData,B44,3))),INDEX(MyData,B44-Period,1):INDEX(MyData,B44,1))


Book1
ABCD
1DateCash flowBalance
231 Jan 1684,62084,620
328 Feb 16084,460
431 Mar 16085,800
530 Apr 16-5,50090,720
631 May 16093,500
730 Jun 169,00084,990
831 Jul 16-1,00086,070
931 Aug 16-2,70087,510
1030 Sep 16089,930
1131 Oct 16087,530
1230 Nov 16087,640
1331 Dec 16092,850
1431 Jan 1730094,980
1528 Feb 1730096,510
1631 Mar 1730094,030
17
18
19XIRRs in detail .JanFebMar
20
2131 Jan 1684,620
2228 Feb 16084,460
2331 Mar 160085,800
2430 Apr 16-5,500-5,500-5,500
2531 May 16000
2630 Jun 169,0009,0009,000
2731 Jul 16-1,000-1,000-1,000
2831 Aug 16-2,700-2,700-2,700
2930 Sep 16000
3031 Oct 16000
3130 Nov 16000
3231 Dec 16000
3331 Jan 17-94,680300300
3428 Feb 17-96,210300
3531 Mar 17-93,730
36
37XIRRs12.16%13.84%8.82%
38
39XIRRs from original table
40(non-contiguous)
41Period12months
42
43XIRRs toHelper
4431 Jan 171312.16%
4528 Feb 171413.84%
4631 Mar 17158.82%
Sheet1
 
Last edited:
Upvote 0
Steve,

Thanks for offering a solution. I'll have to spend a little more time studying the details of your suggestion. Perhaps I've missed something, but it appears that you have created a separate helper table from which to pull data into the formula in C44. If that is the case, unfortunately, the number of accounts, the extent of the actual data in each account, and the dynamic nature of the data makes creating such a work area impractical. Please correct me if I've misinterpreted your solution. As I mentioned in my original posting, one of my preferences is to avoid having to create this type of work area. Ultimately, my goal is to generate XIRRs for the 12, 36, and YTD periods directly from the original data (in this small sample, A2:C16). I'll keep looking at your suggestion.

Thanks, again, for all your help.
Robert
 
Upvote 0
Thanks.

My suggested solution picks up non-contiguous cells from the original data set, as you requested.

The secondary table is just to demonstrate that these calculations replicate a simple XIRR using a helper table. You can delete this table without affecting my formulae.

The table also shows the numbers actually used in my XIRR calculations, which are slightly different to those in your helper table. Hence, for example, my XIRR of 8.82% for the 12 months to 31 March 2017 vs your 9.18% (because we have used 31 March 2017 cashflows of -93,730 and -94,030 respectively).

I did use one helper cell per calculation, and forgot to show this formula above:

C44: =XIRR(IF(ROW(INDIRECT(B44-Period & ":" & B44))=B44-Period,INDEX(MyData,B44-Period,3),INDEX(MyData,B44-Period,2):INDEX(MyData,B44,2)-IF(ROW(INDIRECT(B44-Period & ":" & B44))=B44,INDEX(MyData,B44,3))),INDEX(MyData,B44-Period,1):INDEX(MyData,B44,1))

where:

Helper cell B44: =MATCH(A44,INDEX(MyData,,1),)

PS - also noticed the 28 Feb 2016 end of month date and wondered whether this should be 29th?
 
Last edited:
Upvote 0
I finally had a chance to look further at your suggestions, along with your follow-up explanation from yesterday. I see that your helper table was completely independent of your XIRR calculation and I'm sorry that I didn't pick up on that earlier. Also, your helper cell B44 does help when I add it to the spreadsheet. Your work is quite complicated. Would it be possible for you to give some sort of conceptual overview of what is happening within the formula in C44? I've used Excel's Formula Evaluation tool, but that only gets me so far.

I should clarify the relationship of the values in columns B and C of my original table. Column C is the ending balance for each month and is the balance after the cash flow in column B during that month. For example, the 31 Mar 16 end balance of 85,800 is after March's cash flow (which happens to be 0). It will also be the value at the start of the next day, 1 Apr 2016, the first day of the 12 month period being considered. It follows then that the 31 Mar 17 end balance of 94,030 is after March's 300 deposit and is the final value (in the negative) that should be used in calculating XIRR. Your helper table is correct for the first values for calculating XIRR. However, I think that the final values in column C of your helper table (cells B33, C34, D35) were derived by subtracting the deposits in column B from the corresponding balances in the original table. I believe that these should be the correct values:

B33=-94,980
C34=-96,510
D35=-94,030
B37=12.52%
C37=14.19%
D37=9.18%

So, I'm not quite sure what has to change in C44 to eliminate the subtraction of the last cash flow. I worked on it for awhile but couldn't get anything to work.

After making the appropriate changes, will any of this work for YTD? I'm not sure how rows 44, 45, and 46 enter the picture, but if it helps simplify anything, I am only interested in the most recent 12, 36, and YTD periods, so the last month considered will always be the last month of data.

Lastly, yes, you are correct about 29 Feb 2016. I inadvertently missed considering leap year.

I hope that I haven't complicated matters too much.

Thanks,
Robert
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top