Google 表格 Countif with Arrayformula

Google Sheets Countif with Arrrayformula

我正在 Google 表格中进行一些动态 Monte Carlo 模拟,使用 COUNTIF 公式进行模拟。有些东西没有按照我想象的方式工作,但我无法确定。我有两列要比较,我需要计算一列中的值大于另一列中的值的实例。如果我通过传播 if 比较公式明确地执行此操作,我将获得正确的结果。但是,如果我用

=countif( A4:A, ">" & B4:B ) 

我没有得到正确的结果。我的 example is at this sheet,单元格 C4 中的数字是出现故障的 COUNTIF,在示例中等于 2,单元格 E4 中的数字是 5,通过传播 F 列中的比较并添加正确的比较,这是正确的计数在 E4.

p1  p2  n           
0.5 0.51    10          
Monte Carlo                 
0.50    0.60    2       5   0
0.90    0.50                1
0.60    0.30                1
0.50    0.60                0
0.40    0.30                1
0.40    0.50                0
0.60    0.70                0
0.60    0.30                1
0.70    0.50                1
0.10    0.30                0

尝试:

=INDEX(SUM(IF(A4:A>B4:B, 1)))

countif有两种情况:

(1) 作为非数组公式,=countif( A4:A, ">" & B4:B ) 会给出与 =countif( A4:A, ">" & B4 ) 相同的结果,即它只会计算 A 大于 .60 的值,给出答案 2。

(2) 作为数组公式,=sum(countif( A4:A, ">" & B4:B )) 将为 B 的每个值 (2+5+9+2...) 给出一个单独的结果,给出答案 56.

如果你想使用 countif,你需要做这样的事情:

=ArrayFormula(countif(A4:A-B4:B,">"&0))