Solved

USING COUNTIF WITH MULTIPLE CRITERIA

Posted on 2002-06-03
7
932 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Article by: dandraka
There are several quick shortcuts that can make your life easier in Microsoft Programs.  These simple tips and tricks will your work more productive and you faster at completing your tasks! MS Word (1) Creating Re-usable Scraps You can create s…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now