简体   繁体   English

Excel 数组countif公式

[英]Excel array countif formula

I want to use COUNTIF function to evaluate how many items out of 2,0,0,5 are greater than 2?我想使用 COUNTIF function 来评估 2,0,0,5 中有多少项大于 2? In Countif function, first argument is range and second is criteria.在 Countif function 中,第一个参数是范围,第二个是条件。 I have tried the below formula.我试过下面的公式。 Even tried using Ctrl+Shift+Enter at the end to evaluate.甚至尝试在最后使用 Ctrl+Shift+Enter 进行评估。 But doesn't seem to work.但似乎不起作用。

=COUNTIF({"2","0","0","5"},">2")

COUNTIF doesn't accept array constants (as far as I know). COUNTIF不接受数组常量(据我所知)。 Try this: 试试这个:

=SUMPRODUCT(--({2,0,0,5}>2))

You could also create a countif-style formula like this (the combination ctrl+shift+enter): 你也可以像这样创建一个countif风格的公式(组合ctrl + shift + enter):

=COUNT(IF({2,0,0,5}>2,1,""))

Recommended reading: Array vs Range 推荐阅读: 数组与范围

Some functions like Offset, SumIf, CountIf, SumIfs, and CountIfs are designed to operate only on (multi-cell) range objects. Offset,SumIf,CountIf,SumIfs和CountIfs等函数只能在(多单元格)范围对象上运行。 Sum, SumProduct, Frequency, Linest, lookup functions, etc. take both range and array objects. Sum,SumProduct,Frequency,Linest,lookup函数等同时包含范围和数组对象。

Array means: {2,0,0,5} 数组意味着: {2,0,0,5}

Range means: 范围意味着:

在此输入图像描述

To use countif, you have to use range in cells, defining the array in the formula on the go will not work. 要使用countif,您必须在单元格中使用范围,在公式中定义数组将无法正常工作。

=COUNTIF(A1:A4,">"&2)

I know this thread is a few years old, but I ended up here with a similar problem (how to use arrays, not ranges, with countif).我知道这个线程已经有几年了,但我在这里遇到了类似的问题(如何使用 arrays,而不是范围,与 countif)。

Although my end goal was a little different (I wanted to find items common to two arrays), I figure the workaround I came up with might be useful for others: I ended up using the "match" function coupled with "isnumber".虽然我的最终目标有点不同(我想找到两个数组共有的项目),但我认为我想出的解决方法可能对其他人有用:我最终使用了“匹配”function 和“isnumber”。 The formula looked like this:公式如下所示:

=isnumber(match({a},{b},0))

this will return an array of true/false which corresponds to the values in {a} that are also in {b}.这将返回一个 true/false 数组,它对应于 {a} 中也存在于 {b} 中的值。 In case it wasn't clear, {a} and {b} are arrays...如果不清楚,{a} 和 {b} 是 arrays...

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

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