Search code examples
google-sheetssumgoogle-sheets-formulaflattengoogle-query-language

How to get sum of n cell above using ARRAYFORMULA


I want to calculate Relative Strength Index that use the sum of 14 day of Gains. I can use SUM function then drag down to the bottom, but I want it to expand infinitely (H16 to H). Is there any way to use ARRAYFORMULA? or I must use appscript? I try many things and can't figure the way out.

enter image description here


Solution

  • try:

    =ARRAYFORMULA(IF(SEQUENCE(COUNTA(G3:G))<14,,
     MMULT(IFERROR(VLOOKUP(ROW(G3:G)-SEQUENCE(1, 14, 0),
     {ROW(G3:G), G3:G}, 2, )*1, 0), SEQUENCE(14, 1, 1, 0))))
    

    enter image description here