0

Why does this formula not work: COUNTIF({1,2,3},2)?

I can use both COUNT() and COUNTIF() with a range, but I can replace the range with a literal array only on COUNT, not on COUNTIF.

If I use LET to first assign the array to a name, then I can use a literal array in COUNTIF, but i get the wrong result.

This is the content of a little test that I am using:

A Notes
1 1
2 2
3 3
4
5 =COUNT(A1:A3)
6 =COUNTIF(A1:A3,2)
7 =COUNT({1,2,3})
8 =COUNTIF({1,2,3},2) Excel doesn't allow to enter this formula
9
10 =LET(a,A1:A3,COUNT(a))
11 =LET(a,A1:A3,COUNTIF(a,2))
12 =LET(a,{1,2,3},COUNT(a))
13 =LET(a,{1,2,3},COUNTIF(a,2)) Excel allows this, but the result is wrong

The following snapshot shows the formulas I'm trying to use:

enter image description here

The following snapshot shows the results:

enter image description here

The following snapshot shows the error message when I try to enter the formula in A8:

enter image description here

1 Answer 1

2

You can't use arrays in place of ranges with any of the *IF(S) formulas. They require ranges.

One can use SUMPRODUCT to do most:

=SUMPRODUCT(--({1,2,3}=2))

This will return an array: {0,1,0} to the SUMPRODUCT which will then sum them and return 1

2
  • Thanks... Do you know if this is documented and what is the reason? Or this limitation exists just because?
    – stenci
    Commented Mar 22, 2022 at 20:59
  • 1
    I am not sure if it is documented, but the documentation only refers to ranges. As to why....I have now idea. Commented Mar 22, 2022 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .