使用工作日函数的Countifs公式

时间:2019-01-04 16:09:30

标签: excel excel-formula

我有一个用于条件格式的公式,该公式根据AG列中的日期突出显示单元格。我从stackoverflow天才那里得到了公式:-)

逻辑:

如果Today()是星期一,如果AG中的日期是上周五,周六和周日,我需要突出显示单元格

如果Today()是星期二至星期五,那么我需要强调一下AG中的日期是否是前一天

该公式在条件格式单元格中效果很好,但我也想将其调整为COUNTIFS公式,这样我就可以计算出符合条件的记录数量。

以下是公式:=OR(AND(WEEKDAY(TODAY())>= 3,WEEKDAY(TODAY())<=6,INT(AG10)=INT(TODAY()-1)),AND(WEEKDAY(TODAY())=2,INT(AG10)>=INT(TODAY()-3),INT(AG10)<=INT(TODAY()-1)))

有人可以帮助我调整它与COUNTIFCOUNTIFS一起使用吗?

2 个答案:

答案 0 :(得分:2)

使用SUMPRODUCT:

=SUMPRODUCT(((WEEKDAY(TODAY())>= 3)*(WEEKDAY(TODAY())<=6)*(INT(AG10:AG100)=INT(TODAY()-1)))+((WEEKDAY(TODAY())=2)*(INT(AG10:AG100)>=INT(TODAY()-3))*(INT(AG10:AG100)<=INT(TODAY()-1))))

如果AG中的日期没有时间部分,则可以使用:

=IF(AND(WEEKDAY(TODAY())>= 3,WEEKDAY(TODAY())<=6),COUNTIF(AG:AG,TODAY()-1),IF(WEEKDAY(TODAY())=2,COUNTIFS(AG:AG,">=" & TODAY() -3,AG:AG,"<="&TODAY()-1),0))

答案 1 :(得分:0)

因此,仅出于完整性考虑(向@Scott Craner道歉以借用他的公式),即使值是日期时间,这也应该起作用:

=IF(AND(WEEKDAY(TODAY())>= 3,WEEKDAY(TODAY())<=6),COUNTIFS(AG:AG,">="&TODAY()-1,AG:AG,"<"&TODAY()),IF(WEEKDAY(TODAY())=2,COUNTIFS(AG:AG,">=" & TODAY() -3,AG:AG,"<"&TODAY()),0))

因为Today()-1是3/1/19 00:00,而Today()是4/1/19 00:00,所以> =第一个而<第二个(例如3/1/19 12: 00)必须是昨天。