Share via

Excel Array formula Problem

Anonymous
2015-10-06T12:16:55+00:00

I have a spreadsheet that compares different investment portfolios and business investments.  T make it comparable it all boils down to IRR.  I have a list of payments in and then a list of valuations at certain dates.  Using an array formula I can calculate the IRR from start to each valuation date and it can be copied and expanded easily (its designed for a novice Excel user to update). 

However, I also want to see the IRR each year as well (not the annualised IRR from start but the growth in the last year.  For this you just need to isolate the valuation at the start, payments in in the year and the value at the end.  Should be simple.

  Column A has dates, C is amounts invested, D is periodic valuations. 

The annualised IRR which works is =XIRR(IF(A$2:A14=A14,D14,IF(A$2:A14<A14,C$3:C14,0)),A$2:A14,0.1)  This identifies the valuation at the target date and then presents cashflows which predate this valuation.  Any cashflow after the vlauation is zero.

Where I'm trying to get an annual IRR the formula is

=XIRR(IF(A$2:A16=A16,D16,IF(A$1:A15=EDATE(A16,-12),J$3:J16,IF(A$2:A16>A16,0,IF(A$2:A16<=EDATE(A16,-12),0,C$3:C16)))),A$2:A16)

It is designed to take the at each date as a cash return, the value a year previoulsy as an investment and any cashflows during the last year as investments.  Any cahsflows before teh first date or after the last date should be zero.

It appears to be delivering the correct values to the XIRR function but not giving the right answer.  Can you help identify what I've done wrong.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2015-10-08T00:00:36+00:00

Errata: This replaces a previous incorrect response, which I deleted, but you might have seen.

Andrew wrote:

Column F is where I'm having trouble and should show for just one year.  I've extracted the numbers relevant to cell F16 on the right and calculated IRR.  The array formula does derive these figures and present them to the XIRR function but it gives the answer of 0%.  It must be something to do witht the starting valuation as F14 & 15 work fine.  F16 is the first valuation where there is a starting balance.

I will explain the problems you encountered below.

But first, I suggest that you array-enter (press ctrl+shift+Enter instead of just Enter) the following formula into F14, then copy F14 down through F29:

=XIRR(IF(ROW($A$2:A14)=ROW($A$2),

     IF(EDATE(A14,-12)<=$A$2, $C$2,

         -INDEX($D$14:$D$29,MATCH(EDATE(A14,-12),$A$14:$A$29))),

     IF(ROW($A$2:A14)=ROW(A14), D14,

     IF((EDATE(A14,-12)<=$A$2:A14)*($A$2:A14<=A14),

         $C$2:C14, 0))),

 IF(ROW($A$2:A14)=ROW($A$2), MAX($A$2,EDATE(A14,-12)),

     $A$2:A14))

Note that there is no need for the helper values in column J.

See the detailed explanation below.

Also, download the file "XIRR calc CORRECTED.xlsx" (click here) [1], and look at F14:F29 in the worksheet "SIA corrected".

[1] https://app.box.com/s/zsaxat0tou570ogyctfqmlkti9yhdiyf


The suggested formula corrects two problems caused by your formula.  They can be seen by using the Evaluate Formula to step until the last step before calculation.

  1. In F19, the formula is effectively (omitting some irrelevant entries):

=XIRR({0;-7200;0;0;-7463;12003},

 {"6/29/2007";"5/20/2008";"5/21/2009";0;"10/5/2007";

  "10/5/2008"})

The key problem is:  the first value is zero.  Consequently, even if XIRR worked properly (see #2), the IRR would be calculated from 6/29/2007, not 10/5/2007, the valuation for the beginning of the 12-month window.

Instead, the first value and date should be -7463 and 10/5/2007, the negated valuation corresponding to the beginning of the 12-month window.

  1. If the first value is zero, XIRR returns the constant 2.98E-9 (approx).  There is no good reason for that.  It is a defect.

However, if we fix problem #1, we avoid problem #2.  The suggested formula does just that.


The suggesed formula passes the following parameters to XIRR.

For the value array:

  1. For the first row, use the initial investment if it is after 12 months prior to the valuation date; otherwise, use the valuation negated.
  2. For the last row (valuation date), use the valuation.
  3. For all other rows, use the investment if the date is between the valuation date and 12 months prior; otherwise, use zero.

For the date array:

  1. For the first row, use the later of initial investment date or 12 months prior to the valuation date.
  2. For all other rows, use the investment or valuation date.

Note that if the corresponding value is zero, the date has no impact on the IRR calculation, even if it is outside the 12-month window.  Also note that if the cell is empty, its "date" and value are zero.

The formula assumes:

  1. There are no valuations before the initial investment.
  2. The first valuation is after the initial investment; or if is on the same date, it is equal to the negated initial investment.
  3. There is a valuation corresponding to 12 months prior to every valuation except when the 12-month window begins before the initial investment.

That is, MATCH always finds an exact match.  I use an "approximate" MATCH -- last parameter is zero implicitly -- only for efficiency.

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-10-13T10:46:59+00:00

    Hi Joe

    Thanks for your post.  I really apprecaite your help with this.

    I've read your post and to be honest until I sit down in a dark room and really concentrate then I won't take it all in.  I've downloaded your corrected worksheet though and it certainly looks like your frmula works.  I'm going to take a proper look at it when I can get some time as I'd like to understand what you've done and how you've done it.  I ma yneed to ask a follow up question or two.

    Thank you again for your time.  I wish I could mark your post VERY helpful!

    Regards

    Andrew

    Was this answer helpful?

    0 comments No comments
  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Anonymous
    2015-10-07T14:25:44+00:00

    Hi Joe

    Thanks for your reply - we're making progress already.  I hadn't spotted the range discrepancies but have corrected them all now.  It had little effect on the results unfortunatley, I had hopef you'd fixed it in your first go.  ;-)

    I've setup a drop box and put my test sheet there.  THe address is https://www.dropbox.com/s/lyclwv7c6hz7q60/XIRR%20calc%20test%20data.xlsx?dl=0

    I hope that works.  I'm afraid its not pretty as its a work in progress to prove a principle and then I can tart it up.

    You will see that column G is showing the IRR from the start to date for each valuation.  Column F is where I'm having trouble and should show for just one year.  I've extracted the numbers relevant to cell F16 on the right and calculated IRR.  The array formula does derive these figures and present them to the XIRR function but it gives the answer of 0%.  It must be something to do witht the starting valuation as F14 & 15 work fine.  F16 is the first valuation where there is a starting balance.

    I look forward to your comments.

    Regards

    Andrew

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-10-06T22:15:37+00:00

    Andrew wrote:

    Column A has dates, C is amounts invested, D is periodic valuations. 

    The annualised IRR which works is =XIRR(IF(A$2:A14=A14,D14,IF(A$2:A14<A14,C$3:C14,0)),A$2:A14,0.1)

    This identifies the valuation at the target date and then presents cashflows which predate this valuation.  Any cashflow after the vlauation is zero.

    The structure of the data is not clear to me.  And we cannot vet the XIRR results without a numerical example.

    Please upload an example Excel file to a file-sharing website (see a list below [1]), and post a response here with the public/share URL.

    Presumably, the above formula is array-entered into row 14.  You say it works.  Okay.

    But ostensibly, I believe it should not work because C3:C14 has fewer elements than A2:A14.  Usually, that results in a syntax error (#VALUE or #REF).

    I believe it seems to work only because A2:A14=A14 is true in row 14, of cousre.  So Excel never evaluates the expression that would result in a #REF error, to wit:  IF(A2:A14<A14,C3:C14,0).false in row 14.

    In any case, again, whether or not the array of values passed to XIRR and the XIRR result is truly correct depends on the numbers.  (TBD)

    Moreover, the formula does not work if it is copied into row 2.  XIRR returns a #N/A error.  Presumably, you do not do that.  It is unclear why not.

    Andrew wrote:

    Where I'm trying to get an annual IRR the formula is

    =XIRR(IF(A$2:A16=A16,D16,

    IF(A$1:A15=EDATE(A16,12),J$3:J16, IF(A$2:A16>A16,0,

    IF(A$2:A16<=EDATE(A16,-12),0,C$3:C16)))), A$2:A16)

    It is designed to take the at each date as a cash return, the value a year previoulsy as an investment and any cashflows during the last year as investments.  Any cahsflows before teh first date or after the last date should be zero.

    It appears to be delivering the correct values to the XIRR function but not giving the right answer.  Can you help identify what I've done wrong.

    It is unclear what is in A1, if anything.

    And is unclear what is in column J.  (My guess:  the corresponding year-end valuation from column D.)

    Moreover, it is unclear what is in rows 15 and 16, given that the previous formula used only rows 2 through 14.

    I assume your data extends through row 16 now, and this formula is array-entered into row 16.


    As for the "incorrect" XIRR result....  Again, we cannot vet it without a concrete numerical example.

    First, note that XIRR always uses the first date as "d0"; that is, as the first date of the series.  So even though you zero cash flows before the beginning of the year, XIRR calculates the IRR based on the time series starting from the date in A2.

    Second , again I am concerned about the different range sizes; to wit: A2:A16 and A1:A15 contain15 cells, but  v. C3:C16 and J3:J16 contain 14 cells.  See below for why that works by coincidence(?).

    Finally, I don't believe the formula is finding the intended dates and corresponding values, if column A is in ascending order.  (Is it?)

    Your formula passes the following arrays to XIRR (written stylistically, not valid Excel syntax), if it is array-entered into row 16:

    =XIRR(

    {IF(A2=A16,D16,IF(A1=EDATE(A16,12),J3,IF(A2>A16,0,

         IF(A2<=EDATE(A16,-12),0,C3))));

     IF(A3=A16,D16,IF(A2=EDATE(A16,12),J4,IF(A3>A16,0,

         IF(A3<=EDATE(A16,-12),0,C4))));

     [....]

     IF(A15=A16,D16,IF(A14=EDATE(A16,12),J16,IF(A15>A16,0,

         IF(A15<=EDATE(A16,-12),0,C16))));

     IF(A16=A16,D16,IF(A15=EDATE(A16,12),#REF,IF(A16>A16,0,

         IF(A16<=EDATE(A16,-12),0,#REF))))},

    A2:A16)

    Since the array extends only to the row that contains the formula, presumably no date in column A is later.  (Again, I assume column A is ascending order.  Is it?)

    Thus, A1:A15=EDATE(A16,12) is never true. So I believe you do not find the year-end date. 

    Also, A2:A16>A16 is never true.  But that might work to your advantage:  fewer zero cash flows at the end.

    FYI, apparently the #REF errors do not cause a problem because A16=A16 is true, of course.  So Excel never evaluates the expressions that result in #REF.


    [1] Some free file-sharing websites.

    Dropbox: http://dropbox.com

    Box.Net: http://www.box.net/files

    MediaFire: http://www.mediafire.com

    FileFactory: http://www.filefactory.com

    FileSavr: http://www.filesavr.com

    RapidShare: http://www.rapidshare.com

    Windows OneDrive: http://onedrive.live.com

    Was this answer helpful?

    0 comments No comments