Solved

USING COUNTIF WITH MULTIPLE CRITERIA

Posted on 2002-06-03
7
936 Views
Last Modified: 2012-06-21
I want to be able to do a COUNTIF on 2 columns at the same time.  So in Column K, I have either a 1, 2 or 3.  In Column L, I have either a 1, 2 or 3.  I want it to count only those rows that have both a "1" in Columns K AND L.  Here's what I've tried, but these don't work.

=COUNTIF(K2:K34,"1")*AND(L2:L34,"1")   I get #VALUE

=COUNTIF(K2:K34,"1")*AND(COUNTIF(L2:L34,"1")) get error message

I've tried using the AND function, but am not sure how to use it with COUNTIF function, if I even can (?????).
0
Comment
Question by:esu4236
  • 3
  • 3
7 Comments
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 7051652
Instead of CountIf try using a combination of IF() with AND() like this...

=IF(AND(K1=1,L1=1),1,"")

Then you can simply Sum the column with the If function to get the count of matching columns containing "1"
0
 

Author Comment

by:esu4236
ID: 7051713
Well, I really don't want to have to add yet another column.  Isn't there another way without doing this?
0
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 7051880
IMHO columns are cheap, time is expensive. Off hand I don't see how you are going to do this using just COUNTIF().

The trouble is that COUNTIF() expects to check the value of every SINGLE cell in a range but you want to compare the values of two cells, so you need to have somewhere to store the results of that comparision before you can count them.

So either you use another column for the comparison result, or else you write your own function which will take a two column rage as it's imput parameter. The function would then compare each pare of cells within it's VBA code and store the intermediate results in a variable, which would then be used to return value of the function.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 6

Accepted Solution

by:
bkpchs237 earned 100 total points
ID: 7051926
esu4236,

You could try an array formula, by entering the following into a cell and pressing ctrl+shift+enter to enter it as an array formula:
=SUM((K2:K34=1)*(L2:L34=1))

Hope this helps.
0
 

Author Comment

by:esu4236
ID: 7052051
Thank you very much BKPCHS237 for your solution.  That worked perfect!!!!!  I knew there had to be a way to do it without adding more columns.  Thanks again - you made my day!!!!!

0
 

Author Comment

by:esu4236
ID: 7052053
Thank you very much BKPCHS237 for your solution.  That worked perfect!!!!!  I knew there had to be a way to do it without adding more columns.  Thanks again - you made my day!!!!!

0
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 7052179
bkpchs237 : as in infrequent user of Excel (I spend most of my days with Access) I am gratefull to you for your enlightening answer - Array functions have been something I've steered clear of before now.

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had the experience that you had to follow 10 steps over and over again every time when you need to nicely forward an important email to your manager? Fear no more! With the help of the Quick Steps feature in Outlook 2010, your old chor…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question