计算列中仅包含特定月份的特定文本的单元格

Count cells in a column that contain certain text only for a certain month

我试图对 E 列中包含单词 "Yelp" 的单元格进行计数,但仅限于某个月份(在本例中为一月)。

由于每个月都会有不同数量的新患者,我无法设置范围限制,例如 E4:E33。由于这个 "E33" 数字会改变,我希望它只是 E(整列),这样我们就不必每个月手动更改公式。

我尝试了 COUNTIFS(MONTH(D4:D), "=1", E4:E, "Yelp") 的不同变体,但它不起作用。使用 "filter" 之类的东西需要每月手动更改公式,所以我不能使用它。

试试这个: 首先添加一列(假设 F)returns 日期 (D)

的月份

F1=MONTH(D1)(并向下拖动)

然后,数:

=COUNTIFS(F:F;4;D:D;'Yelp');

即:仅当月份为 4 且来源为 Yelp

时才计数

编辑:

我想您也想按年份过滤。在这种情况下,添加一列 returns 年份:

G1=YEAR(D1)(并向下拖动),然后:

=COUNTIFS(F:F;4;G:G;2018;D:D;'Yelp');

即:仅当月份为4,年份为2018,来源为Yelp

时才计算

解释:

COUNTIFS 的语法是:

COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)

The COUNTIFS function syntax has the following arguments:

criteria_range1 Required. The first range in which to evaluate the associated criteria.

criteria1 Required. The criteria in the form of a number, expression, cell reference, or text that define which cells will be counted. For example, criteria can be expressed as 32, ">32", B4, "apples", or "32".

criteria_range2, criteria2, ... Optional. Additional ranges and their associated criteria. Up to 127 range/criteria pairs are allowed.

来自:https://support.office.com/en-us/article/countifs-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842

试试,

=sumproduct((month(d4:d999)=1)*(e4:e999="yelp"))
'alternate with fully dynamic ranges
=sumproduct((month(d4:index(d:d, match(1e99, d:d)))=1)*(e4:index(e:e, match(1e99, d:d))="yelp"))

避免使用 SUMPRODUCT 引用完整的列。