[英]EXcel COUNT values based on multiple conditions in different ranges
I have an Excel spreadsheet, contain all possible combinations between certain products, eg aa, ab, ac, ba, bb, bc, ca, cb and cc
. 我有一个Excel电子表格,其中包含某些产品之间的所有可能组合,例如aa, ab, ac, ba, bb, bc, ca, cb and cc
。 Based on those combinations, a value is calculated and compared with a historical value. 基于这些组合,可以计算一个值并将其与历史值进行比较。 The two values are subtracted, resulting in -1, 0 or 1. 两个值相减,得出-1、0或1。
Now, in another spreadsheet, I have all the products listed (so that would be a, b and c here) and for each product, I would like to know how many -1's, 0's and 1's the product had as a result when it was the second product in the combination, eg I want to know how many ...-b's resulted in 0. 现在,在另一个电子表格中,我列出了所有产品(因此这里是a,b和c),对于每个产品,我想知道该产品在结果时有多少个-1、0和1。是组合中的第二个乘积,例如,我想知道多少...- b产生0。
My first thought was to use a simple COUNTIF
, going over the range with the subtraction: COUNTIF(RANGE:0)
. 我的第一个想法是使用一个简单的COUNTIF
,用减法来计算范围: COUNTIF(RANGE:0)
。 Of course, this gives all the 0's in the range, without taking into account the product. 当然,这会给出范围内的所有0,而不考虑乘积。 Then, I tried SUM(IF(AND("range of the second product"="b";"range of the subtraction result"=0);1))
, but this produces #N/A
. 然后,我尝试了SUM(IF(AND("range of the second product"="b";"range of the subtraction result"=0);1))
,但这会产生#N/A
I am unsure what to try out next. 我不确定接下来要尝试什么。
In some other related topics, the suggestion was made to make use of arrays, based on http://www.cpearson.com/excel/ArrayFormulas.aspx 在其他一些相关主题中,建议基于http://www.cpearson.com/excel/ArrayFormulas.aspx使用数组。
Consequently, I tried the formula {=COUNT(("2ndproductrange"="b") * ("resultrange"<0))}
, but this returned the total number of rows. 因此,我尝试了公式{=COUNT(("2ndproductrange"="b") * ("resultrange"<0))}
,但这返回了总行数。 A variant with {=COUNTIF(("2ndproductrange"="b")*("resultrange");<0)}
isn't a valid formula. 带有{=COUNTIF(("2ndproductrange"="b")*("resultrange");<0)}
变体不是有效的公式。
It sounds like to me that you are trying to perform a COUNT
operation that matches 2 distinct criteria. 在我看来,您正在尝试执行与2个不同条件匹配的COUNT
操作。 As you noted the COUNTIF
formula takes in a single criteria, well there is a COUNTIFS
formula that takes in multiple. 如您所述, COUNTIF
公式采用单个条件,而COUNTIFS
公式采用多个条件。 Here is what I "think" it would look like with your example ranges: 这是我“认为”您的示例范围所显示的内容:
=COUNTIFS(2ndproductrange;"b";resultrange;"<0")
A concrete example would be as follows: 一个具体的例子如下:
A B C D E F G
---------------------------------------------------------
Historical Value Product Countifs a b c
1 c <0 1 2 0
-1 a 0 0 1 1
-1 b >0 1 2 1
1 b
1 b
0 c
-1 b
0 b
1 a
In the above example the formulas would be: 在上面的示例中,公式为:
=COUNTIFS($B:$B;"a";$A:$A;"<0") =COUNTIFS($B:$B;"b";$A:$A;"<0") =COUNTIFS($B:$B;"c";$A:$A;"<0")
=COUNTIFS($B:$B;"a";$A:$A;"0") =COUNTIFS($B:$B;"b";$A:$A;"0") =COUNTIFS($B:$B;"c";$A:$A;"0")
=COUNTIFS($B:$B;"a";$A:$A;">0") =COUNTIFS($B:$B;"b";$A:$A;">0") =COUNTIFS($B:$B;"c";$A:$A;">0")
For those that are using a comma ,
as their list separator locale the same formulas would be: 对于使用逗号,
作为列表分隔符区域设置)的用户,相同的公式为:
=COUNTIFS($B:$B,"a",$A:$A,"<0") =COUNTIFS($B:$B,"b",$A:$A,"<0") =COUNTIFS($B:$B,"c",$A:$A,"<0")
=COUNTIFS($B:$B,"a",$A:$A,"0") =COUNTIFS($B:$B,"b",$A:$A,"0") =COUNTIFS($B:$B,"c",$A:$A,"0")
=COUNTIFS($B:$B,"a",$A:$A,">0") =COUNTIFS($B:$B,"b",$A:$A,">0") =COUNTIFS($B:$B,"c",$A:$A,">0")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.