Google Sheets Formula to calculate actual total duration of tasks with different start/end dates, overlaps, and gaps

久未见 提交于 2020-01-24 18:07:33

问题


I know I how to do this using a custom function/script but I am wondering if it can be done with a built-in formula.

I have a list of tasks with a start date and end date. I want to calculate the actual # of working days (NETWORKDAYS) spent on all the tasks.

  • Task days may overlap so I can't just total the # of days spent on each task
  • There may be gaps between tasks so I can't just find the difference between the first start and last end.

For example, let's use these:

| Task Name | Start Date | End Date   | NETWORKDAYS |
|:---------:|------------|------------|:-----------:|
|     A     | 2019-09-02 | 2019-09-04 |      3      |
|     B     | 2019-09-03 | 2019-09-09 |      5      |
|     C     | 2019-09-12 | 2019-09-13 |      2      |
|     D     | 2019-09-16 | 2019-09-17 |      2      |
|     E     | 2019-09-19 | 2019-09-23 |      3      |

Here it is visually:

Now:

  • If you total the NETWORKDAYS you'll get 15
  • If you calculate NETWORKDAYS between 2019-09-02 and 2019-09-23 you get 16

But the actual duration is 13:

  • A and B overlap a bit
  • There is a gap between B and C
  • There is a gap between D and E

If I was to write a custom function I would basically take all the dates, sort them, find overlaps and remove them, and account for gaps.

But I am wondering if there is a way to calculate the actual duration using built-in formulas?


回答1:


sure, why not:

=ARRAYFORMULA(COUNTA(IFERROR(QUERY(UNIQUE(TRANSPOSE(SPLIT(CONCATENATE("×"&
 SPLIT(REPT(INDIRECT("B1:B"&COUNTA(B1:B))&"×", 
 NETWORKDAYS(INDIRECT("B1:B"&COUNTA(B1:B)), INDIRECT("C1:C"&COUNTA(B1:B)))), "×")+
 TRANSPOSE(ROW(INDIRECT("A1:A"&MAX(NETWORKDAYS(B1:B, C1:C))))-1)), "×"))), 
 "where Col1>4000", 0))))



来源:https://stackoverflow.com/questions/58140221/google-sheets-formula-to-calculate-actual-total-duration-of-tasks-with-different

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!