根据条件对出现次数进行计数

时间:2019-06-19 21:21:39

标签: excel-formula

我有一个简单的数据框,其中包含4列日期,名称,迟到和提早离开。我正在尝试计算过去30天内某个人晚/早出现的次数。

我尝试使用countcountif失败。

Date     Name    Late    Leave
08/01    John    9:05    
         Sue    10:01
08/02    Bob             4:51    
08/03    Sue     9:16
         John            3:10
08/04
08/05    Bob     9:19
08/06    Sue             3:30

我尝试过=countifs(B2:B8,B2,C2:D8,"<>"),但收到值错误。我也尝试使用诸如{=count(if(B2:B8=B2,C2:D8))}之类的数组公式,但是没有得到想要的结果。我什至没有尝试合并30天,因为我什至无法使其在当前状态下正常运行。

例如,我要计算的是:

John had a total of 2 late/leave early in the month of August
Sue had a total of 3 late/leave early in the month of August
etc.

2 个答案:

答案 0 :(得分:1)

COUNTIFS要求范围的大小必须相同。您将需要做两个并将它们添加在一起:

=COUNTIFS(B:B,F2,C:C,"<>")+COUNTIFS(B:B,F2,D:D,"<>")

enter image description here

答案 1 :(得分:0)

您需要在每个单元格中填写日期,以确保最大的准确性。

在下面的公式中,将$ G $ 1替换为包含目标日期或Today()的单元格。

要获取问题中所述的目标日期前30天的出现次数,请使用以下公式:

=COUNTIFS(
$B$2:$B$9,$F4,$C$2:$C$9,"<>""",$A$2:$A$9,">="&$G$1-30,$A$2:$A$9,"<="&$G$1)+
COUNTIFS(
$B$2:$B$9,$F4,$C$2:$C$9,"<>""",$D$2:$D$9,">="&$G$1-30,$A$2:$A$9,"<="&$G$1)

enter image description here

但是,如果要查找目标日期月份中的出现次数,请使用以下公式:

=COUNTIFS(
$B$2:$B$9,$F4,$C$2:$C$9,">0",$A$2:$A$9,">="&EOMONTH($G$1,-1)+1,$A$2:$A$9,"<"&EOMONTH($G$1,0)+1)+
COUNTIFS(
$B$2:$B$9,$F4,$D$2:$D$9,">0",$A$2:$A$9,">="&EOMONTH($G$1,-1)+1,$A$2:$A$9,"<"&EOMONTH($G$1,0)+1)

enter image description here