简体   繁体   English

具有多个条件和表的COUNTIF公式

[英]COUNTIF formula with multiple criteria and table

I have a list of four developers (A1="Dev1", A2="Dev2", A3="Dev3" and A4="Dev3"). 我有四个开发人员的列表(A1 =“ Dev1”,A2 =“ Dev2”,A3 =“ Dev3”和A4 =“ Dev3”)。

Within a working week calendar, I have 5 columns, one for each day of the week (C1="Monday", D1="Tuesday", E1="Wednesday", F1="Thursday, G1="Friday"). 在一个工作周日历中,我有5列,一周中的每一天(C1 =“ Monday”,D1 =“ Tuesday”,E1 =“ Wednesday”,F1 =“ Thursday,G1 =” Friday“)。

If developer Dev3 has a day off on Tuesday, I'd go to D2 and input: "Dev3". 如果开发人员Dev3在星期二休息一天,我将去D2并输入:“ Dev3”。

On H2, I have the following formula: 在H2上,我有以下公式:

=COUNTIF(C2:G2,"*Dev1*")+COUNTIF(C2:G2,"*Dev2*")+COUNTIF(C2:G2,"*Dev3*")+COUNTIF(C2:G2,"*Dev4*") = COUNTIF(C2:G2,“ * Dev1 *”)+ COUNTIF(C2:G2,“ * Dev2 *”)+ COUNTIF(C2:G2,“ * Dev3 *”)+ COUNTIF(C2:G2,“ * Dev4 * ”)

In the scenario above, I'd have the value of H2 being '1'. 在上述情况下,我将H2的值设为“ 1”。 If I edit D2 cell to something like this: "Dev3,Dev4", the result of H2 would be '2'. 如果我将D2单元格编辑为以下内容:“ Dev3,Dev4”,则H2的结果将为'2'。

This formula works well for what I need but I know that there is a more elegant way that I could use the list of the developers on A:A column, instead of creating a single COUNTIF element per developer. 这个公式可以很好地满足我的需要,但是我知道,还有一种更优雅的方法可以使用A:A列上的开发人员列表,而不是为每个开发人员创建单个COUNTIF元素。

Could anyone help me achieving the usage of the list A:A instead of creating a single COUNTIF element for every single developer, instead? 有谁能帮助我实现列表A:A的用法,而不是为每个开发人员都创建一个COUNTIF元素?

sheet's screenshot: 工作表的屏幕截图:

OP样本数据图像

Either a SUM / COUNTIF function array¹ formula or a SUMPRODUCT function should be able to count correctly providing there are no 'false positives' like Dev1 found in Dev12 . SUM / COUNTIF函数数组¹公式或SUMPRODUCT函数应该能够正确计数, 前提是Dev12中找不到像Dev1这样的“误报”。

'array formula
=SUM(COUNTIF(C2:G2, "*"&A$1:INDEX(A:A, MATCH("zzz",A:A ))&"*"))
'SUMPRODUCT
=SUMPRODUCT(--ISNUMBER(SEARCH(A$1:INDEX(A:A, MATCH("zzz",A:A )), C2:G2)))

Note that in both cases, the list of developers from column A has been cut down to the minimum number of cells with, 请注意,在这两种情况下,A列中的开发人员列表均已缩减为具有

A$1:INDEX(A:A, MATCH("zzz",A:A ))

Dev1_Dev2


¹ Array formulas need to be finalized with Ctrl + Shift + Enter↵ . ¹ 数组公式需要使用Ctrl + Shift + Enter↵完成 Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. 正确输入第一个单元格后,就可以像填充其他公式一样向下或向右填充或复制它们。 Try and reduce your full-column references to ranges more closely representing the extents of your actual data. 尝试将全列引用减少到更接近代表实际数据范围的范围。 Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. 数组公式对数地缩短了计算周期,因此,最好将参考范围缩小到最小。 See Guidelines and examples of array formulas for more information. 有关更多信息,请参见准则和数组公式示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM