将两个日期之间的元素重复 n 次,并在其旁边标明日期
repeat n times an element between 2 dates and indicate the dates right next to it
如何在两个日期之间重复一个元素并指明日期
输入值:
ID
Begin
End
ST00
May 15 2022
May 15 2022
TE01
May 23 2022
May 25 2022
TO01
May 16 2022
May 19 2022
预期输出:
ID
Date
ST00
May 15 2022
TE01
May 23 2022
TE01
May 24 2022
TE01
May 25 2022
TO01
May 16 2022
TO01
May 17 2022
TO01
May 18 2022
TO01
May 19 2022
我现在在做什么:
E2
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY( REPT(A2:A&"~", if(A2:A="",,C2:C-B2:B+1)),,9^9), "~"))))
在 F2 中(并向下方拖动)
=countif(E:E2,E2)
G2
=arrayformula(iferror(vlookup(E2:E,A:B,2,0)+F2:F-1))
有没有办法去掉 F 列?
使用:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(IF(DAYS(C2:C, B2:B)>=SEQUENCE(1, 1000, ),
IF(A2:A="",,A2:A&"×"&TEXT(B2:B+SEQUENCE(1, 1000, ), "mmm dd e")), )), "×"),
"where Col2 is not null", ))
更快:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(IF(DAYS(C2:C, B2:B)>=SEQUENCE(1, MAX(C2:C-B2:B+1), ),
IF(A2:A="",,A2:A&"×"&TEXT(B2:B+SEQUENCE(1, MAX(C2:C-B2:B+1), ), "mmm dd e")), )), "×"),
"where Col2 is not null", ))
与@player0 类似的公式,但我喜欢将结束列用作构造数组中的“额外”列,以便查询进行比较。
这是一个 sample sheet created specifically to solve this problem,可以在 A2 中名为 'output'
的选项卡上找到该公式
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(Data!A2:A&"|"&Data!B2:B+SEQUENCE(1,MAX(Data!C2:C-Data!B2:B),0)&"|"&Data!C2:C),"|",0,0),"select Col1,Col2 where Col2<=Col3"))
如何在两个日期之间重复一个元素并指明日期
输入值:
ID | Begin | End |
---|---|---|
ST00 | May 15 2022 | May 15 2022 |
TE01 | May 23 2022 | May 25 2022 |
TO01 | May 16 2022 | May 19 2022 |
预期输出:
ID | Date |
---|---|
ST00 | May 15 2022 |
TE01 | May 23 2022 |
TE01 | May 24 2022 |
TE01 | May 25 2022 |
TO01 | May 16 2022 |
TO01 | May 17 2022 |
TO01 | May 18 2022 |
TO01 | May 19 2022 |
我现在在做什么:
E2
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY( REPT(A2:A&"~", if(A2:A="",,C2:C-B2:B+1)),,9^9), "~"))))
在 F2 中(并向下方拖动)
=countif(E:E2,E2)
G2
=arrayformula(iferror(vlookup(E2:E,A:B,2,0)+F2:F-1))
有没有办法去掉 F 列?
使用:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(IF(DAYS(C2:C, B2:B)>=SEQUENCE(1, 1000, ),
IF(A2:A="",,A2:A&"×"&TEXT(B2:B+SEQUENCE(1, 1000, ), "mmm dd e")), )), "×"),
"where Col2 is not null", ))
更快:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(IF(DAYS(C2:C, B2:B)>=SEQUENCE(1, MAX(C2:C-B2:B+1), ),
IF(A2:A="",,A2:A&"×"&TEXT(B2:B+SEQUENCE(1, MAX(C2:C-B2:B+1), ), "mmm dd e")), )), "×"),
"where Col2 is not null", ))
与@player0 类似的公式,但我喜欢将结束列用作构造数组中的“额外”列,以便查询进行比较。
这是一个 sample sheet created specifically to solve this problem,可以在 A2 中名为 'output'
的选项卡上找到该公式=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(Data!A2:A&"|"&Data!B2:B+SEQUENCE(1,MAX(Data!C2:C-Data!B2:B),0)&"|"&Data!C2:C),"|",0,0),"select Col1,Col2 where Col2<=Col3"))