Home > Net >  How to repeat a LAMBDA generated sequence of dates a certain number of times in Google Sheets
How to repeat a LAMBDA generated sequence of dates a certain number of times in Google Sheets

Time:11-27

I have a LAMBDA function nested in a lambda helper function (MAKEARRAY) to create a column with a series of dates. The series starts with the last day of the month defined in cell start_date followed by the last day of the following month. This one month interval goes on a number of times defined by the value in cell number_months.

The formula is the following:

=MAKEARRAY(number_months,1,LAMBDA(r,c,EOMONTH(start_date,r-1)))

I would like:

  • This sequence to repeat just below.
  • Repetition needs to take place a certain number of times, as defined by value in number_repeats.

Since I have the series as the row heading of another Sheet, I have tried using TRANSPOSE(ARRAYFORMULA(INDIRECT to select the variable range, rather than generating again the repeated series of dates. However, in such case I have to figure out how to repeat that array a certain number of times without using REPT and SPLIT because it exceeds the character capacity by far.

That being said, if possible my preference is for a solution based on the transposed LAMBDA function that created the row heading in the other Sheet, rather than referring to the heading using ARRAYFORMULA.

I feel I could use SEQUENCE for that, but I am not sure how to combine it with the LAMBDA function to repeat the series a certain number of times.

CodePudding user response:

What do you think of this?? You can change that B1:1 of the last pair of brackets to your own lambda function. For visual purposes (and probably of calculations if they're too long) I used a range of headers in B1:1 and cell A1 to state the "n" number of times.

So, "qt" is the amount of items in the "headers" (done with Counta) and "times" is that number set by you. I used Counta so you could be able to add more items in your headers (or lambda function) and it would be flexible enough to work too.

BYROW displays the range, and SEQUENCE calculates the amount of rows needed (qt*times) and MOD and INDEX iterates through the headers the amount of times needed.

=lambda(qt,headers,lambda(times,byrow(sequence(qt*times),lambda(seq,INDICE(headers,,RESIDUO(seq-1,times) 1))))(CONTARA(headers)))(A1,B1:1)

Here you have a sample sheet: enter image description here

I have formatted the dates manually though.

  • Related