Using countif function with values in non-adjacent cells

I'm trying to use countif function to do a conditional count for cells in non-adjacent rows. Below is a simple example of what I'm trying to do. The image shows that only the cells I want the count to be based on are highlighted. But instead of giving a result of 2 (2 of the 4 cells contain the value 3), it gives 0. I have tried various conditions but never get a correct result. What am I doing wrong?


Thanks in advance!



MacBook Pro 15″, macOS 12.6

Posted on Apr 4, 2023 6:24 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 4, 2023 8:06 PM

COUNTIF takes an array as the first argument. You are using + to add up different cells. Numbers doesn't interpret that as an array.


Normally you would just do something like this:



=COUNTIF(A,3)



But if you must explicitly exclude A2, A4, A6, A8 for some reason then you can do something like this:




=COUNTIF({A1,A3,A5,A7,A9},3)



If your region uses , as the decimal separator then it will look like this:




=COUNTIF({A1.A3.A5.A7.A9};3)



SG

3 replies
Question marked as Top-ranking reply

Apr 4, 2023 8:06 PM in response to melzie

COUNTIF takes an array as the first argument. You are using + to add up different cells. Numbers doesn't interpret that as an array.


Normally you would just do something like this:



=COUNTIF(A,3)



But if you must explicitly exclude A2, A4, A6, A8 for some reason then you can do something like this:




=COUNTIF({A1,A3,A5,A7,A9},3)



If your region uses , as the decimal separator then it will look like this:




=COUNTIF({A1.A3.A5.A7.A9};3)



SG

Apr 5, 2023 1:17 PM in response to Yellowbox

According to Apple's Numbers Reference Guide, COUNTIF expects a range OR a "collection" (non-adjacent cells). The problem was trying to get the right syntax for a collection. When I selected individual cells, the app inserted the + sign, not me. The answer is as posted by SG, using curly brackets. None of the examples in Apple's Numbers Reference Guide showed that.


Thanks for all the replies!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using countif function with values in non-adjacent cells

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.