Solved

COUNTIF

Posted on 2012-03-19
5
280 Views
Last Modified: 2012-03-20
Hello Everyone

I have a sheet with data.. example

Column 1    Column 2
Apple 1          Pear 1
Apple 2          Pear 2
Apple 1          Pear 1
Apple 3          Pear 6
Apple 1          Pear 7

Another Sheet With:

Column 1      Column 2
Apple 1              2
Apple 2               1
Apple 3              1
Apple 4              1

Is basically looking at column 2 of sheet 1 to determine how many unique entries
belong to Apple 1 etc...

I hope I made sense.
0
Comment
Question by:Friggin_Lazy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 48

Expert Comment

by:Martin Liss
ID: 37740291
Your example seems faulty. There are 3 'Apple 1' not 2.
0
 
LVL 8

Expert Comment

by:csoussan
ID: 37740351
As Martin stated above, the count for Apple 1 seems incorrect in your example as there are three listed.  However, assuming that the number 2 is just a typo, I think the following formula will do what you need.

=COUNTIF(Sheet1!A2:B6,A2)

I've attached a spreadsheet with your first set of columns in Sheet1 and the second set of columns (with formulas) on Sheet2.  Note - You can use COUNTIFS in place of COUNTIF and still get the same results.  The upside to COUNTIFS is you can list multiple criteria.

Hope this helps!
COUNTIF.xlsx
0
 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 37740393
Yes, there are indeed 2 distinct Apple 1's (you have to look at column B as well, correct?)

Put this formula in Sheet 2, cell B2

[B2]=SUMPRODUCT((Sheet1!$A$2:$A$6=$A2)*IF(COUNTIF(Sheet1!$B$2:$B$6,Sheet1!$B$2:$B$6)=0,"",1/COUNTIF(Sheet1!$B$2:$B$6,Sheet1!$B$2:$B$6)))

Hit CTRL-SHIFT+Enter to confirm as an array formula.  Then, copy down as needed.  Note the bounds of the formula are to row 6, so you can extend that as needed.

See attached and I get the same results you do, except there is no Apple 4 in the first sheet, lol ;)

Dave
countApples-r1.xls
0
 
LVL 18

Expert Comment

by:krishnakrkc
ID: 37740547
Hi

Another option..

=COUNT(IF(FREQUENCY(IF(Sheet1!$A$2:$A$6=A2,MATCH(Sheet1!$B$2:$B$6,Sheet1!$B$2:$B$6,0)),ROW(Sheet1!$A$2:$A$6)-ROW(Sheet1!$A$2)+1),1))

Array formula. Confirmed with CTRL + SHIFT + ENTER

Kris
0
 

Author Closing Comment

by:Friggin_Lazy
ID: 37741098
Thank You Dave!  This is exactly what I was looking for.  I also appricate the attachment as an example!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

628 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