Finding and adding together overlaps in dates from 2 different columns in excel

后端 未结 2 774
北荒
北荒 2020-12-21 15:44

I have 2 tables on my excel workbook. One to track tasks and one to track leave. I want to see the impact leave would have on each tasks (i.e. the total number of leave days

2条回答
  •  旧巷少年郎
    2020-12-21 16:12

    Apologies for late posting but this has taken a bit of thought. One way to do it is to generate an array of all the days in November, then test the array elements one at a time against each pair of leave dates to see if they fall within those dates, using countifs. So the basic formula is

    =SUMPRODUCT(COUNTIFS($H$2:$H$7,$A2,$I$2:$I$7,"<="&ROW(INDIRECT($C2&":"&$D2)),$J$2:$J$7,">="&ROW(INDIRECT($C2&":"&$D2))))
    

    However we want to ignore weekends, so to do this I set all weekend dates to zero before counting up the matches

    =SUMPRODUCT(COUNTIFS($H$2:$H$7,$A2,$I$2:$I$7,"<="&ROW(INDIRECT($C2&":"&$D2))*(WEEKDAY(ROW(INDIRECT($C2&":"&$D2)),2)<=5),$J$2:$J$7,">="&ROW(INDIRECT($C2&":"&$D2))))
    

    A fairly long formula but it seems to give the correct results.

    Columns E, L and M are for checking only and are not part of the final result in column F.

提交回复
热议问题