0

Here is my data:

date            value     repeat    offset
10 September    6         3         1
5 September     5         0         0
11 September    7         0         0

I would like the repeats to create new entries, with the offset of offset, in months, so this should output, I have been looking at query and arrayformula, but have no idea how this is best achieved:

date            value
10 September    6    
10 October      6    
10 November     6    
5 September     5    
11 September    7    
TheMaster
  • 45,448
  • 6
  • 62
  • 85
Himmators
  • 14,278
  • 36
  • 132
  • 223

2 Answers2

1

enter image description here

  • add a column with ids for each row (column A in my sample)

F2 =TRANSPOSE(SPLIT(TEXTJOIN("",1,TRANSPOSE(ARRAYFORMULA(TEXT(ROW(INDIRECT("a1:a"&MAX(D2:D4)))*(TRANSPOSE(D2:D4)>=ROW(INDIRECT("a1:a"&MAX(D2:D4)))),"0"","";;")))),","))

G2 =TRANSPOSE(SPLIT(JOIN("", filter(REPT(A2:A&",",D2:D),A2:A<>"")) , ","))

H2 =FILTER(VLOOKUP(G2:G,{A:A,B:B},2,),G2:G<>"")

I2 =FILTER( DATE(YEAR(EOMONTH(H2:H,F2:F-1)), MONTH(EOMONTH(H2:H,F2:F-1)), day(H2:H)) ,G2:G<>"")

J2 =FILTER(VLOOKUP(G2:G,{A:A,C:C},2,),G2:G<>"")

More samples of counters here.

Max Makhrov
  • 17,309
  • 5
  • 55
  • 81
0

Date is a reserved word so I renamed it.. And the SQL is taken from Oracle.

WITH DATA (ADATE,VALUE,REPEAT,OFFSET) AS(
SELECT DATE '2018-09-10',    6,         3,         1 FROM DUAL UNION ALL
SELECT DATE '2018-09-05',     5,         2,         1 FROM DUAL UNION ALL
SELECT DATE '2018-09-11',    7,         2,         1 FROM DUAL 
),
REPEATING AS (
SELECT LEVEL LVL, D.* 
FROM DATA D
CONNECT BY LEVEL <= D.REPEAT
AND PRIOR ADATE = ADATE
and prior sys_guid() is not null
)

SELECT add_months(ADATE,OFFSET*(lvl-1)) "date", value "value"
from repeating;

gives the following result:

enter image description here

W_O_L_F
  • 1,049
  • 1
  • 9
  • 16