Search code examples
google-sheetsgoogle-sheets-formula

Start sequence on a variable column without "array not expanded" error?


In one sheet, I have columns for each month. In another sheet, I define start countdown in: with a cell 04/2023 and # of months as 4.

The desired result is starting under April 2023, I want to see a countdown of 4, 3, 2, 1 for four months.

I can use the formula =sequence(1, Rules!$B$26 + 1, Rules!$B$26, -1) but only if I manually add it under April 2023.

I tried doing =if(text(B1,"MMyyyy")=text(Rules!$B$25,"MMyyyy"),sequence(1, Rules!$B$26 + 1, Factors!$B$26, -1),) for all the cells in the row, but it gives the error "Array result was not expanded because it would overwrite data"


Solution

  • Here's a generalized scenario of how it can be done:

    =index(xlookup(A$1:L$1,edate(N2,sequence(O2,1,0,1)),sequence(O2,1,O2,-1),))
    
    • the rules are in Columns N,O of this sample dataset

    enter image description here