Search code examples
google-sheetsgoogle-sheets-formula

Populate dates based on frequency


I am hoping to populate dates based on the start date and frequency up until the end date.

Input (this list will grow):

+ A B C D E F
1 Start Date End Date Frequency Cost Category  Company
2 02/02/2024 17/02/2024 14 545 Cow First Farmers
3 03/02/2024 17/02/2024 7 23 Sheep Outbacks
4 07/02/2024 17/02/2024 3 23 Pigs Cowboys first

Making the output:

+ A B C D E
1 Date Frequency Cost Category  Company
2 02/02/2024 14 545 Cow First Farmers
3 03/02/2024 7 23 Sheep Outbacks
4 07/02/2024 3 23 Pigs Cowboys first
5 10/02/2024 7 23 Sheep Outbacks
6 10/02/2024 3 23 Pigs Cowboys first
7 13/02/2024 3 23 Pigs Cowboys first
8 16/02/2024 14 545 Cow First Farmers
9 16/02/2024 3 23 Pigs Cowboys first
10 17/02/2024 7 23 Sheep Outbacks

I have worked out how to get the first row, but only the date using:

=ARRAYFORMULA( IFERROR( Sheet1!$A$2 + (SEQUENCE((Sheet1!$B$2 - Sheet1!$A$2) / Sheet1!$C$2 + 1, 1, 0) * Sheet1!$C$2) ) 

I made a EXAMPLE_SHEET so it may be easier to understand


Solution

  • Here's one approach you may test out:

    =sort(let(Ξ,tocol(,1), reduce(Ξ,Input!A2:index(Input!A:A,match(,0/(Input!A:A<>""))),lambda(a,c,vstack(if(iserror(a&""),Ξ,a),let(x,offset(c,,1),y,offset(c,,2),Σ,quotient(x-c,y)+1,if(or(c="",x=""),Ξ,
     hstack(sequence(Σ,1,c,y),chooserows(offset(c,,2,,4),sequence(Σ,1,1,0))))))))),1,1,2,)
    

    enter image description here