My question is simple: when I replace a range (array) with the corresponding VSTACK function, my formula returns weird results.
I am working on a financial model that I have simplified for this post. I have the returns of an asset, month by month, that I want to compound (that is, I give the initial and ending month of my calculation). In the example given, I want to know the total return from month 1 to 2, from month 2 to 4 and from month 1 to 5.
The "from to" months appear in a range. When I use the range directly in my formula, the results are correct, as it is proven below in the check range.
However, if I use the VSTACK function, the function does not work, it gives incorrect returns. It seems to take into account only the "from" month, without paying any attention to the "to" month at all.
It is the first time that I encounter a problem like this one with VSTACK.
The problem that I have is that in my model, the range of "from...to" months expands to the right, so that I cannot use the formula based on the simple range.
I am not obliged to use the VSTACK function, any function that works on dynamic arrays is fine for me, provided that it works, of course.
My questions are: 1- why do you think the VSTACK function is not working in my model? 2- what alternative formulas could I use instead that works on dynamic array (that expand).
Formula that doesn't work:
=BYCOL(VSTACK(J3#;J4#);LAMBDA(c;PRODUCT(1+INDEX(C4:G4;;SEQUENCE(1;INDEX(c;2)-INDEX(c;1)+1;INDEX(c;1))))-1))
Formula that works, but it is not exactly what I need:
=BYCOL(J3:L4;LAMBDA(c;PRODUCT(1+INDEX(C4:G4;;SEQUENCE(1;INDEX(c;2)-INDEX(c;1)+1;INDEX(c;1))))-1))
I am using the International setting for Spain. Thank you
I have proved that VSTACK does not work by using a simple fixed range instead, as it is shown on the picture above.
The result expected is also shown in the picture.
I have simplified my model to the maximum before posting my question.
My question resembles a little the one whose title is "VSTACK (and TEXTSPLIT) on dynamic ranges" but I do not think that the problem is exactly the same.
Put @
in front of the three INDEXES inside the SEQUENCE:
=BYCOL(VSTACK(J3#,J4#),LAMBDA(c,PRODUCT(1+INDEX(C4:G4,,SEQUENCE(1,@INDEX(c,2)-@INDEX(c,1)+1,@INDEX(c,1))))-1))
REMEMBER that you need to replace the ,
with ;
for your locale.