如何在不同日期启动countif

时间:2019-01-17 17:51:46

标签: excel excel-formula

我的文件超过30,000行,我需要计算每半小时每天的发生次数(但必须为3:05,3:35,4:05 ...),我有一年数据的。 A列具有日期,B列具有时间,C列具有我添加的值,以检查每半小时有多少次出现。

Column A    Column B    Column C
1/12/19      3:37 PM     12:05 AM
1/11/19      2:27 PM     12:35 AM
1/11/19      5:37 PM     1:05 AM
1/10/19      8:32 PM     1:35 AM

这是我的公式所具有的功能,如果我指定了范围,但是由于我每天有数百行,因此我需要它每隔一天才开始计数。

=IF(AND(P3>=$AD$3,P3<=$AD$4),COUNTIFS($P$3:$P$17,">="&$AD$3,$P$3:$P$17,"<="&AD$4),IF(AND(P3>=$AD$4,P3<=$AD$5),COUNTIFS($P$3:$P$17,">="&$AD$4,$P$3:$P$17,"<="&$AD$5),IF(AND(P3>=$AD$5,P3<=$AD$6),COUNTIFS($P$3:$P$17,">="&$AD$5,$P$3:$P$17,"<="&$AD$6),IF(AND(P3>=$AD$6,P3<=$AD$7),COUNTIFS($P$3:$P$17,">="&$AD$6,$P$3:$P$17,"<="&$AD$7),IF(AND(P3>=$AD$7,P3<=$AD$8),COUNTIFS($P$3:$P$17,">="&$AD$7,$P$3:$P$17,"<="&$AD$8),IF(AND(P3>=$AD$8,P3<=$AD$9),COUNTIFS($P$3:$P$17,">="&$AD$8,$P$3:$P$17,"<="&$AD$9),IF(AND(P3>=$AD$9,P3<=$AD$10),COUNTIFS($P$3:$P$17,">="&$AD$9,$P$3:$P$17,"<="&$AD$10),IF(AND(P3>=$AD$10,P3<=$AD$11),COUNTIFS($P$3:$P$17,">="&$AD$10,$P$3:$P$17,"<="&$AD$11),IF(AND(P3>=$AD$11,P3<=$AD$12),COUNTIFS($P$3:$P$17,">="&$AD$11,$P$3:$P$17,"<="&$AD$12),IF(AND(P3>=$AD$12,P3<=$AD$13),COUNTIFS($P$3:$P$17,">="&$AD$12,$P$3:$P$17,"<="&$AD$13),IF(AND(P3>=$AD$13,P3<=$AD$14),COUNTIFS($P$3:$P$17,">="&$AD$13,$P$3:$P$17,"<="&$AD$14),IF(AND(P3>=$AD$14,P3<=$AD$15),COUNTIFS($P$3:$P$17,">="&$AD$14,$P$3:$P$17,"<="&$AD$15),IF(AND(P3>=$AD$15,P3<=$AD$16),COUNTIFS($P$3:$P$17,">="&$AD$15,$P$3:$P$17,"<="&$AD$16),IF(AND(P3>=$AD$16,P3<=$AD$17),COUNTIFS($P$3:$P$17,">="&$AD$16,$P$3:$P$17,"<="&$AD$17),IF(AND(P3>=$AD$17,P3<=$AD$18),COUNTIFS($P$3:$P$17,">="&$AD$17,$P$3:$P$17,"<="&$AD$18),IF(AND(P3>=$AD$18,P3<=$AD$19),COUNTIFS($P$3:$P$17,">="&$AD$18,$P$3:$P$17,"<="&$AD$19),IF(AND(P3>=$AD$19,P3<=$AD$20),COUNTIFS($P$3:$P$17,">="&$AD$19,$P$3:$P$17,"<="&$AD$20),IF(AND(P3>=$AD$20,P3<=$AD$21),COUNTIFS($P$3:$P$17,">="&$AD$20,$P$3:$P$17,"<="&$AD$21),IF(AND(P3>=$AD$21,P3<=$AD$22),COUNTIFS($P$3:$P$17,">="&$AD$21,$P$3:$P$17,"<="&$AD$22),IF(AND(P3>=$AD$22,P3<=$AD$23),COUNTIFS($P$3:$P$17,">="&$AD$22,$P$3:$P$17,"<="&$AD$23),IF(AND(P3>=$AD$23,P3<=$AD$24),COUNTIFS($P$3:$P$17,">="&$AD$23,$P$3:$P$17,"<="&$AD$24),IF(AND(P3>=$AD$24,P3<=$AD$25),COUNTIFS($P$3:$P$17,">="&$AD$24,$P$3:$P$17,"<="&$AD$25),IF(AND(P3>=$AD$25,P3<=$AD$26),COUNTIFS($P$3:$P$17,">="&$AD$25,$P$3:$P$17,"<="&$AD$26),IF(AND(P3>=$AD$26,P3<=$AD$27),COUNTIFS($P$3:$P$17,">="&$AD$26,$P$3:$P$17,"<="&$AD$27),IF(AND(P3>=$AD$27,P3<=$AD$28),COUNTIFS($P$3:$P$17,">="&$AD$27,$P$3:$P$17,"<="&$AD$28),IF(AND(P3>=$AD$28,P3<=$AD$29),COUNTIFS($P$3:$P$17,">="&$AD$28,$P$3:$P$17,"<="&$AD$29),IF(AND(P3>=$AD$29,P3<=$AD$30),COUNTIFS($P$3:$P$17,">="&$AD$29,$P$3:$P$17,"<="&$AD$30),IF(AND(P3>=$AD$30,P3<=$AD$31),COUNTIFS($P$3:$P$17,">="&$AD$30,$P$3:$P$17,"<="&$AD$31),IF(AND(P3>=$AD$31,P3<=$AD$32),COUNTIFS($P$3:$P$17,">="&$AD$31,$P$3:$P$17,"<="&$AD$32),IF(AND(P3>=$AD$32,P3<=$AD$33),COUNTIFS($P$3:$P$17,">="&$AD$32,$P$3:$P$17,"<="&$AD$33),IF(AND(P3>=$AD$33,P3<=$AD$34),COUNTIFS($P$3:$P$17,">="&$AD$33,$P$3:$P$17,"<="&$AD$34),IF(AND(P3>=$AD$34,P3<=$AD$35),COUNTIFS($P$3:$P$17,">="&$AD$34,$P$3:$P$17,"<="&$AD$35),IF(AND(P3>=$AD$35,P3<=$AD$36),COUNTIFS($P$3:$P$17,">="&$AD$35,$P$3:$P$17,"<="&$AD$36),IF(AND(P3>=$AD$36,P3<=$AD$37),COUNTIFS($P$3:$P$17,">="&$AD$36,$P$3:$P$17,"<="&$AD$37),IF(AND(P3>=$AD$37,P3<=$AD$38),COUNTIFS($P$3:$P$17,">="&$AD$37,$P$3:$P$17,"<="&$AD$38),IF(AND(P3>=$AD$38,P3<=$AD$39),COUNTIFS($P$3:$P$17,">="&$AD$38,$P$3:$P$17,"<="&$AD$39),IF(AND(P3>=$AD$39,P3<=$AD$40),COUNTIFS($P$3:$P$17,">="&$AD$39,$P$3:$P$17,"<="&$AD$40),IF(AND(P3>=$AD$40,P3<=$AD$41),COUNTIFS($P$3:$P$17,">="&$AD$40,$P$3:$P$17,"<="&$AD$41),IF(AND(P3>=$AD$41,P3<=$AD$42),COUNTIFS($P$3:$P$17,">="&$AD$41,$P$3:$P$17,"<="&$AD$42),IF(AND(P3>=$AD$42,P3<=$AD$43),COUNTIFS($P$3:$P$17,">="&$AD$42,$P$3:$P$17,"<="&$AD$43),IF(AND(P3>=$AD$43,P3<=$AD$44),COUNTIFS($P$3:$P$17,">="&$AD$43,$P$3:$P$17,"<="&$AD$44),IF(AND(P3>=$AD$44,P3<=$AD$45),COUNTIFS($P$3:$P$17,">="&$AD$44,$P$3:$P$17,"<="&$AD$45),IF(AND(P3>=$AD$45,P3<=$AD$46),COUNTIFS($P$3:$P$17,">="&$AD$45,$P$3:$P$17,"<="&$AD$46),IF(AND(P3>=$AD$46,P3<=$AD$47),COUNTIFS($P$3:$P$17,">="&$AD$46,$P$3:$P$17,"<="&$AD$47),IF(AND(P3>=$AD$47,P3<=$AD$48),COUNTIFS($P$3:$P$17,">="&$AD$47,$P$3:$P$17,"<="&$AD$48),IF(AND(P3>=$AD$48,P3<=$AD$49),COUNTIFS($P$3:$P$17,">="&$AD$48,$P$3:$P$17,"<="&$AD$49),IF(AND(P3>=$AD$49,P3<=$AD$50),COUNTIFS($P$3:$P$17,">="&$AD$49,$P$3:$P$17,"<="&$AD$50),"NO IN RANGE"))))))))))))))))))))))))))))))))))))))))))))))

1 个答案:

答案 0 :(得分:0)

步骤1:

您不需要在现有数据旁边放置C列(如上面的问题所示),而是需要一个单独的表,其中包含您要计数的所有日期和时间,如下所示:

Set Up Date Table

第2步:

我还建议您用Insert into #BidYTDRegions (Code,APAC,EMEA,NAMerica,LAMerica) select 'Payroll' ,(select Count(*) from DashboardData where DataType = 'Bid' and SMHQRegion = 'APAC' and Services like '%Streamline Payroll%') ,(select Count(*) from DashboardData where DataType = 'Bid' and SMHQRegion = 'EMEA' and Services like '%Streamline Payroll%') ,(select Count(*) from DashboardData where DataType = 'Bid' and SMHQRegion = 'N. America' and Services like '%roll%') ,(select Count(*) from DashboardData where DataType = 'Bid' and SMHQRegion = 'L. America' and Services like '%roll%') 替换当前的C列数据,以便在单个单元格中拥有日期和时间。

第3步:

完成所有操作后,您只需在“计数”列中使用以下公式即可:

=A2+B2

在公式中,将[RangeWithYourDateTimeData]替换为更新的C列范围(确保使用$$)。 另外[PeriodStart]和[Next PeriodStart]代表您要计算的时间段的上限和下限(将这些引用替换为步骤1中新表中的适用单元格)。对于我的屏幕截图,我会将这个公式放在单元格=COUNTIFS([RangeWithYourDateTimeData],">=" & [PeriodStart],[$RangeWithYourDateTimeData],"<" & [Next PeriodStart])B2[PeriodStart]=A2中。然后向下拖动。