Link to home
Create AccountLog in
Microsoft Excel

Microsoft Excel

--

Questions

--

Followers

Top Experts

Avatar of maximus1974
maximus1974

How to count multiple values in an Excel formula.
What is the proper syntax in an Excel formula to count multiple values.

Ex. I want to know the amount records that appear with both 02 and 03 in the same column. I currently have the formula only counting 02.

Screenshot attached.
Capture.PNG

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


SOLUTION
Avatar of Subodh Tiwari (Neeraj)Subodh Tiwari (Neeraj)🇮🇳

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

SOLUTION
Avatar of Glenn RayGlenn Ray🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of Subodh Tiwari (Neeraj)Subodh Tiwari (Neeraj)🇮🇳

@Glenn
If you use Sumproduct as suggested by me, you don't need to place an Array formula that is where Sumproduct has an edge over Sum function as Sumproduct can handle arrays.

Avatar of Glenn RayGlenn Ray🇺🇸

I'm not suggesting that the array function is any better then SUMPRODUCT, just that it is another alternative. Frankly, the COUNTIF solution you offered is the simplest and best, IMO.

Avatar of Subodh Tiwari (Neeraj)Subodh Tiwari (Neeraj)🇮🇳

Agree. Countif is good if there are only few criteria but if there are multiple criteria, it would look ugly to join multiple Countif functions. So obviously Sumproduct/Sum would be a good alternative in that case and easy to tweak as well.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


ASKER CERTIFIED SOLUTION
Avatar of byundtbyundt🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of Glenn RayGlenn Ray🇺🇸

^Yep.  Just a minor correction (close bracket):
=SUM(COUNTIF(A12:A400,{"02","03"}))

Avatar of byundtbyundt🇺🇸

Glenn,
Thanks for catching my goof on the second formula. I edited it to read correctly.
Brad

Avatar of Subodh Tiwari (Neeraj)Subodh Tiwari (Neeraj)🇮🇳

Good one Brad! :)

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of maximus1974maximus1974

ASKER

Why do I keep getting the error attached?
Capture.PNG

Avatar of byundtbyundt🇺🇸

I can reproduce your error message by using two single-quote characters instead of the required double-quote character in the array constant.

Avatar of Subodh Tiwari (Neeraj)Subodh Tiwari (Neeraj)🇮🇳

It seems you missed the SUM part of the formula and also I guess you should use ; (semi-colon) instead of comma as per your regional settings.
Try this to see if that works for you.....

=SUM(COUNTIF(A12:A400;{"02";"03"}))

Open in new window


Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Subodh Tiwari (Neeraj)Subodh Tiwari (Neeraj)🇮🇳

Yeah that might be the case as well.

Avatar of byundtbyundt🇺🇸

maximus1974 has an IP address in New York City, so commas are the correct list separator. I am betting the problem is just the single quote instead of double quote.

If the formula is copied from the code snippet below and pasted in maximus1974's workbook, it should work without error.
=SUM(COUNTIF(A12:A400,{"02","03"}))

Open in new window


I keep getting the same error wen copying it directly from the code snippet. Two screenshots attached.
Capture.PNG
Capture2.PNG

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Subodh Tiwari (Neeraj)Subodh Tiwari (Neeraj)🇮🇳

See which one of the following works for you...

=SUM(COUNTIF(A12:A400|{"02","03"}))

Open in new window

OR
=SUM(COUNTIF(A12:A400|{"02"|"03"}))

Open in new window


Avatar of byundtbyundt🇺🇸

maximus1974,
If you use a US version of Excel, I strongly suggest that you change your list separator character to a comma. I've never seen anyone use a pipe symbol like shown in Capture2.PNG in the Region and Language...Customize Format...Numbers control panel--and if you post questions on an Excel forum, everybody assumes that you use a comma as the list separator.

Brad

Avatar of Subodh Tiwari (Neeraj)Subodh Tiwari (Neeraj)🇮🇳

The chosen answers resolved the question.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Microsoft Excel

Microsoft Excel

--

Questions

--

Followers

Top Experts

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.