Why does a specific arrayformula not work in google sheets but works fine in excel

允我心安 提交于 2019-12-11 06:49:09

问题


This is in continuation to how to calculate XIRR dynamically in excel and in google sheets

The proposed array formula** solution (mentioned below) works perfectly fine in excel

=XIRR(INDEX(F:G,N(IF(1,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)),ROW(INDEX(A:A,1):INDEX(A:A,COUNTIF(B$2:B$8,J2)))))),N(IF(1,{1,2}))),CHOOSE({1,2},INDEX(A:A,N(IF(1,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)),ROW(INDEX(A:A,1):INDEX(A:A,COUNTIF(B$2:B$8,J2))))))),TODAY()))

but the same solution refuses to work in google sheets with the error

In XIRR evaluation, the value array must include positive and negative numbers.

Any idea why this is not working in google sheets and how to make it work?

Source data

    PurchaseDate    Script  No.ofunits  PurchNAVrate    NetAmount            ForXIRR    TotalReturn
    17/11/2014          A   2241            33              75000           -75000          96000
    8/1/2015            B   53              649             35000           -35000          43000
    14/1/2015           B   75              658             50000           -50000          61500
    14/10/2014          C   2319            32              75000           -75000          108000
    8/1/2015            D   318             109             35000           -35000          40000
    14/1/2015           D   450             110             50000           -50000          57000
    8/6/2015            D   175             114             20000           -20000          22000



Values for Fund A should be around 14%  
Values for Fund B should be around 13%
Values for Fund C should be around 21%
Values for Fund D should be around 8%

回答1:


It appears that the the constructions which allow us to generate an array of returns from INDEX, i.e.:

N(IF(1,,,

or

N(INDEX(,,,

are valid in Excel but not in Google Sheets, in the latter both resolving to just a single (i.e. the first) element in the array passed.

For example, in Excel, the following:

=SUM(INDEX(A1:A10,N(IF(1,{1,2,7}))))

or:

=SUM(INDEX(A1:A10,N(INDEX({1,2,7},))))

will sum the values in A1, A2 and A7, though in Google Sheets both will sum only the value in A1.

I do not know enough about Google Sheets to know why this is the case. It may be possible to reconstruct my formula using the volatile OFFSET. I will have a look and get back to you.

Update: It appears that even an OFFSET-based solution, i.e.:

=XIRR(N(OFFSET(F2,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)-MIN(ROW(B$2:B$8))),ROW(INDIRECT("1:"&COUNTIF(B$2:B$8,J2)))),{0,1})),CHOOSE({1,2},N(OFFSET(A2,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)-MIN(ROW(B$2:B$8))),ROW(INDIRECT("1:"&COUNTIF(B$2:B$8,J2)))),{0,1})),TODAY()))

is not possible. Again, it works fine in Excel but not in Google Sheets, for reasons similar to those given above (the arrays passed to OFFSET do not resolve as required).

I think this requires an explanation by someone well-versed in Google Sheets.

References:

https://excelxor.com/2014/09/05/index-returning-an-array-of-values/

Regards



来源:https://stackoverflow.com/questions/39228169/why-does-a-specific-arrayformula-not-work-in-google-sheets-but-works-fine-in-exc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!