开始和结束日期的数组,其中开始的开始日期=上一个结束日期+1 WORKDAY

时间:2019-12-18 05:13:49

标签: date google-sheets google-sheets-formula array-formulas google-sheets-query

是否可以使用一个公式将两列日期(开始和结束)包含每个任务的初始开始日期和天数?我可以将公式向下拖动,但如果可能的话,我希望具有ARRAYFORMULA的灵活性。

我有一份任务清单(会不断变化),其中有几天的时间来完成每个任务。我也有一个确定的开始日期。我可以使用WORKDAY

获取结束日期
=ArrayFormula(IF(LEN(B2:B),WORKDAY.INTL(C2:C-1,B2,6,),))

,但是尝试自动填充下一个开始日期总是会产生循环引用。

=ArrayFormula(WORKDAY.INTL(C2:C,B2:B,6,))

下一个问题是在WORKDAY函数的[weekend]变量中。由于我的下一个开始日期并非总是在同一天,因此“ 6”并不总是准确的,导致周末无意中显示为有效的工作日。

Here's my test sheet

enter image description here

1 个答案:

答案 0 :(得分:1)

为什么不这样做:

粘贴到单元格 D2

=ARRAYFORMULA(FILTER(
 QUERY(TO_DATE(ROW(INDIRECT(DATEVALUE(C2)&":"&DATEVALUE(C2)+SUM(B2:B)*2))), 
 "where not dayofweek(Col1) matches '1|7'"), 
 IF(REGEXMATCH(TO_TEXT(ROW(INDIRECT("A1:A"&COUNTA(
 QUERY(TO_DATE(ROW(INDIRECT(DATEVALUE(C2)&":"&DATEVALUE(C2)+SUM(B2:B)*2))), 
 "where not dayofweek(Col1) matches '1|7'"))))), "^"&JOIN("$|^", 
 IF(A2:A="",,MMULT(TRANSPOSE((ROW(A2:A)<=TRANSPOSE(ROW(A2:A)))*(B2:B)), 
 SIGN(B2:B))))&"$"), "♀", )="♀"))

粘贴到单元格 C3

=ARRAYFORMULA(IF(A3:A="",,FILTER(
 QUERY(TO_DATE(ROW(INDIRECT(DATEVALUE(C2)&":"&DATEVALUE(C2)+SUM(B2:B)*2))), 
 "where not dayofweek(Col1) matches '1|7'"), 
 IF(REGEXMATCH(TO_TEXT(ROW(INDIRECT("A1:A"&COUNTA(
 QUERY(TO_DATE(ROW(INDIRECT(DATEVALUE(C2)&":"&DATEVALUE(C2)+SUM(B2:B)*2))), 
 "where not dayofweek(Col1) matches '1|7'"))))), "^"&JOIN("$|^", 
 IF(A2:A="",,MMULT(TRANSPOSE((ROW(A2:A)<=TRANSPOSE(ROW(A2:A)))*(B2:B)), 
 SIGN(B2:B))+1))&"$"), "♀", )="♀")))

0


带有假期列表:

=ARRAYFORMULA(FILTER(
 QUERY(TO_DATE(ROW(INDIRECT(DATEVALUE(C2)&":"&DATEVALUE(C2)+SUM(B2:B)*2))), 
 "where not dayofweek(Col1) matches '1|7' and not Col1 matches '"&
 TEXTJOIN("|", 1, H2:H)&"'"), 
 IF(REGEXMATCH(TO_TEXT(ROW(INDIRECT("A1:A"&COUNTA(
 QUERY(TO_DATE(ROW(INDIRECT(DATEVALUE(C2)&":"&DATEVALUE(C2)+SUM(B2:B)*2))), 
 "where not dayofweek(Col1) matches '1|7' and not Col1 matches '"&
 TEXTJOIN("|", 1, H2:H)&"'"))))), "^"&JOIN("$|^", 
 IF(A2:A="",,MMULT(TRANSPOSE((ROW(A2:A)<=TRANSPOSE(ROW(A2:A)))*(B2:B)), 
 SIGN(B2:B))))&"$"), "♀", )="♀"))

0