Compare columns, count matches

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm looking to compare two lists (a1:a10 compared to b1:b10, unnamed). Then,
return the count of original matches between the two lists. For example, if
Joe Schmidt shows once in a1:a10 and twice in b1:b10, then count it only once.

Any advice greatly appreciated? Thank in advance.

P.S. = this will be incorporated into an If statement.
 
Try this:

=SUMPRODUCT(--(ISNUMBER(MATCH(A1:A10,B1:B10,0))))
if Joe Schmidt shows once in a1:a10 and twice in b1:b10,
then count it only once.

If Joe Schmidt shows up more than once in A1:A10 and at least once in B1:B10
each instance in A1:A10 will be counted.

Biff
 
One interp & play, presuming that what you're really after is to extract the
uniques list of names within A1:B20

In A11: =IF(B1="","",B1)
Copy A11 down to A20

In D1:
=IF(A1="","",IF(COUNTIF($A$1:A1,A1)>1,"",ROW()))

In E1:
=IF(ROW()>COUNT(D:D),"",INDEX(A:A,SMALL(D:D,ROW())))
Select D1:E1, copy down to E20. Col E returns the list of unique names
within A1:B20, all neatly bunched at the top.

And if you also want the count of the unique names extracted in col E:
In F1, copy down to F20:
=IF(E1="","",COUNTIF(A:A,E1))
 
maybe i am confused but let's try anyway

D1 = Joe Schmidt

=SUM((A1:A10=B1:B10)*(A1:A10=D1)*{1})
hit ctrl-shft-enter..
 
Try this:

=SUMPRODUCT(CEILING(COUNTIF(A1:A100,B1:B100)*0.001,1))

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP
 
So, you only want to count the *uniques* in column A that also appear in
column B?

Try this:

Entered as an array using the key combination of CTRL,SHIFT,ENTER (not just
ENTER):

=SUM(N(FREQUENCY(IF((ISNUMBER(MATCH(A1:A10,B1:B10,0)))*(ISNUMBER(A1:A10)),MATCH(A1:A10&"",A1:A10&"",0)),MATCH(A1:A10&"",A1:A10&"",0))>0))

............A..........B
1........10.............
2........22.........10
3........10.........10
4........17.........30
5........10.........22
6.....................22
7........22..........0

The result based on the above example is 2.

Biff
 
Well THAT sure didn't work as soon as I put some duplicates in.

***********
Regards,
Ron

XL2002, WinXP
 
I tested this using numbers and so the formula has an expression that tests
for numbers.

(ISNUMBER(A1:A10))

This change will work for text or numbers or both (array entered):

=SUM(N(FREQUENCY(IF((ISNUMBER(MATCH(A1:A10,B1:B10,0)))*(A1:A10<>""),MATCH(A1:A10&"",A1:A10&"",0)),MATCH(A1:A10&"",A1:A10&"",0))>0))

Biff
 
No prob. Thanks for the feedback. On retrospect, think my original take
on your intent was perhaps a bit wayward <g>. Can see that you've got
quite a number of other responses to try since, besides Biff's follow
ups. It's good if you would take the time to post some feedback to
*all* responders who offer you their thoughts on your problem.
 
Try it on this data set:

............A..........B
1........10.............
2........22.........10
3........10.........10
4........17.........30
5........10.........22
6.........0..........22
7........22.............

Then put another 0 in B7. Also seems to get tripped up on formula blanks.

Biff
 
Try it on this data set:

............A..........B
1........10..........0
2........22.........10
3........10.........10
4........17.........30
5........10.........22
6.....................22
7........22..........0

Or, this one:

............A..........B
1........10..........0
2........22.........10
3........10.........10
4........17.........30
5........10.........22
6.........0..........22
7........22..........0

Biff
 
Hey, Biff....I'm a bit puzzled by your post.

This formula
=SUMPRODUCT((COUNTIF(A1:A20,B1:B20&"")>0)/COUNTIF(B1:B20,B1:B20&"")*(B1:B20<>""))

.....returns 2 for this one, which is correct (10 and 22 are hits)
.............A..........B
1........10..........0
2........22.........10
3........10.........10
4........17.........30
5........10.........22
6.....................22
7........22..........0

....and returns 3 for this one, also correct (10, 22 and 0 are hits)
.............A..........B
1........10..........0
2........22.........10
3........10.........10
4........17.........30
5........10.........22
6.........0..........22
7........22..........0

Are you saying it works?
or am I missing something?

***********
Regards,
Ron

XL2002, WinXP
 
Ok, I figured out what the problem was. See these screencaps:

http://img153.imageshack.us/img153/9568/uniquesdiverr2od.jpg

http://img186.imageshack.us/img186/5438/uniquesnoerr4zf.jpg

You'll notice in the first screencap the result of the formula is a #DIV/0!
error and in the 2nd screencap the result is correct.

Notice the range in the formula used in the first screencap and the range
used in the formula in the 2nd screencap. Although I don't know this to be
fact, I think this type of formula has a problem with the used range. I
mentioned this in a thread several months ago and Bob Phillips verified that
he also experienced this before.

In the first screencap the formula references exceed the current used range.
In the 2nd screencap I changed the references to be within the current used
range.

Try this test. I'm using Excel 2002 on WinXP (all updates current)

Open a *new fresh empty* workbook.
Enter this formula in B1:

=SUMPRODUCT((A1:A10<>"")/COUNTIF(A1:A10,A1:A10&""))

The result is 0 as you'd expect since the referenced range is empty.
Now, start entering data in A1 and on down one cell at a time.
The formula returns #DIV/0! until an entry is made in A10. This also sets
the used range referenced in the formula.
Now, if you clear the contents of the range and then start entering new data
the formula works as expected.

Another one of Excel's "features"!

So, your formula does in fact work and I like it!!!!!!!!!

Biff
 
Biff

I ran your scenario and (of course) ran into the DIV/0 error.

I only see 2 ways around it (neither very attractive):

1)Dynamic Range Names
Example:
Name: rngListOne
Refers to:
=OFFSET(Sheet8!$A$1,0,0,MAX(INDEX((Sheet8!$A$1:$A$20<>"")*ROW(Sheet8!$A$1:$A$20),0)),1)

2)This hideous thing:
=SUMPRODUCT((COUNTIF(A1:INDEX(A1:A20,MAX(INDEX((A1:A20<>"")*ROW(A1:A20),0))),B1:INDEX(B1:B20,MAX(INDEX((B1:B20<>"")*ROW(B1:B20),0)))&"")>0)/COUNTIF(B1:INDEX(B1:B20,MAX(INDEX((B1:B20<>"")*ROW(B1:B20),0))),B1:INDEX(B1:B20,MAX(INDEX((B1:B20<>"")*ROW(B1:B20),0)))&"")*(B1:INDEX(B1:B20,MAX(INDEX((B1:B20<>"")*ROW(B1:B20),0)))<>""))

The best pre-emptive solution is to just make sure the used range includes
the referenced range.

Thanks for taking the time to help me work through this one.
I think I'll put this formula in my stash.

***********
Best Regards,
Ron

XL2002, WinXP
 
I'd opt for the dynamic named range.

I "discovered" this setting up a template. I needed to extract uniques from
a range and couldn't figure out why it didn't work. I knew the formula was
correct. As soon as I used the dynamic range it worked as expected.
I think I'll put this formula in my stash.

It's now in mine!

Good job!

Biff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top