如何计算Excel中两个截止date之间的天数

我有一个Excel工作簿,看起来像这样

Year Date Was the office open? 2016-01-01 Y 2016-01-02 Y 2016-01-03 N 2016-01-04 N 2016-01-05 N 2016-01-06 Y 2016-01-07 Y 2016-01-08 Y 2016-01-09 Y 2016-01-10 Y 2016-01-11 N 2016-01-12 Y 2016-01-13 Y 2016-01-14 Y 2016-01-15 Y 2016-01-16 N 2016-01-17 Y 2016-01-18 Y 2016-01-19 Y 2016-01-20 Y 2016-01-21 Y 2016-01-22 Y 2016-01-23 Y 2016-01-24 Y 2016-01-25 Y 2016-01-26 Y 2016-01-27 N 2016-01-28 Y 2016-01-29 Y 2016-01-30 Y 2016-01-31 Y 2016-02-01 Y 2016-02-02 Y 

在工作簿中有另一个电子表格,如下所示

 Period Cutoff Dates 2016-01-01 2016-01-06 2016-01-12 2016-01-16 2016-01-27 2016-02-02 

我想要的是一种基于Y / N的查询和计数,它根据date(或第一个date)和前一个date的差异来告诉我该期间办公室开放的天数。 我想看到这个

 Year Date Was the office open? Days office was open in the period 2016-01-01 Y 2016-01-02 Y 2016-01-03 N 2016-01-04 N 2016-01-05 N Count the number of 'Y' between 2016-01-01 and 2016-01-06 less 1 day, show 2 in the 3rd column 2016-01-06 Y 2016-01-07 Y 2016-01-08 Y 2016-01-09 Y 2016-01-10 Y 2016-01-11 N Count the number of 'Y' between 2016-01-06 and 2016-01-12 less 1 day, show 5 in the 3rd column 2016-01-12 Y 2016-01-13 Y 2016-01-14 Y 2016-01-15 Y Count the number of 'Y' between 2016-01-12 and 2016-01-16 less 1 day, show 4 in the 3rd column 2016-01-16 N 2016-01-17 Y 2016-01-18 Y 2016-01-19 Y 2016-01-20 Y 2016-01-21 Y 2016-01-22 Y 2016-01-23 Y 2016-01-24 Y 2016-01-25 Y 2016-01-26 Y Count the number of 'Y' between 2016-01-16 and 2016-01-27 less 1 day, show 10 in the 3rd column 2016-01-27 N 2016-01-28 Y 2016-01-29 Y 2016-01-30 Y 2016-01-31 Y 2016-02-01 Y 2016-02-02 Y Count the number of 'Y' between 2016-01-27 and 2016-02-02, show 6 in the 3rd column 

这应该很容易。 我只是不能到达那里。 任何帮助,将不胜感激。

谢谢JM

尝试这个:

 =IF(COUNTIF(Sheet25!$A:$A,Sheet24!A2+1),COUNTIFS($A:$A,">=" & INDEX(Sheet25!$A:$A,MATCH(Sheet24!A2,Sheet25!$A:$A)),$A:$A,"<="&INDEX(Sheet25!$A:$A,MATCH(Sheet24!A2,Sheet25!$A:$A)+1)-1,$B:$B,"Y"),"") 

使用短名单将Sheet25更改为您的工作表名称。

放入C2并复制下来。

![在这里输入图片描述