PDA

View Full Version : Solved: CountIf, or maybe something else



GreenTree
10-28-2008, 12:26 PM
Not sure if I should be using an array function, or a CountIf, or something else here. Any help will be much appreciated!

Here's the task: I have a grid which is populated by 2-letter ID's. Above the grid, I will have a line showing desired ID's. I'd like to compute a score for each row of the table showing how many entries match the desired ID's, in the same column. Simple example

Desired: AA DE BC
. Line 1 AB XA BC Score = 1 (BC)
. Line 2 AC BC DE Score = 0 (nothing matches the Desired ID in the same column)
. Line 3 AA DE JJ Score = 2 (AA and DE match)

The actual table is about 35 columns by 500 rows, and the Desired entires will be updated by the users. I could use another worksheet to create a duplicate grid populated by a statement like
=if ( {grid entry!R,C} = {Line 1 entry!R1,C}, 1, 0 )
and sum across the row to get the score, but I'd prefer to avoid the extra worksheet if it can be done. I also need to keep the workbook compatible with Open Office, which rules out using a VBA solution, so I need to do this all with formulas.

As best I can tell, CountIf looks at static comparisons, with no ability to refer to the cell at the top of the respective column. I'm not smart enough on array functions to figure out if some form of SumIf will work for this or not.

Anyone?

Many thanks,

G.T.

mdmackillop
10-28-2008, 01:09 PM
A simple solution, but there must be a better one
=SUM((B2 = B$1),(C2 = C$1),(D2 =D$1))

gearcutter
10-28-2008, 01:10 PM
Hi, try the simple way;

=SUM(IF($A$1=A2,1,0),IF($B$1=B2,1,0),IF($C$1=C2,1,0))

Regards Howard

RichardSchollar
10-28-2008, 01:11 PM
Hi

Assuming your top line is A1:C1 and the grid is A2:C4 then:

=SUMPRODUCT(--(A2:C2=$A$1:$C$1))

in D2 copied down.

Richard

mdmackillop
10-28-2008, 01:21 PM
Hi

Assuming your top line is A1:C1 and the grid is A2:C4 then:

=SUMPRODUCT(--(A2:C2=$A$1:$C$1))

in D2 copied down.

Richard
I knew there was a better way. Thankfully there was an Excel MVP around to point it out.
Congratulations
Malcolm

RichardSchollar
10-28-2008, 02:00 PM
Thank you Malcolm :)

GreenTree
10-28-2008, 04:14 PM
And thank you, Richard!

Exactly the solution I was hoping for. Thread is solved; may I inquire as to the function of the "--" in the expression?

With gratitude,

G.T.

mdmackillop
10-28-2008, 04:24 PM
It forces True/False to 1/0 allowing the results to be added and produce the Sum.
Check out this site (http://www.xldynamic.com/) (when it's available again) for more on SumProduct

GreenTree
10-28-2008, 07:41 PM
Thank you, Malcolm.

However, being impatient, I found the article cached with Google, here (http://74.125.45.104/search?q=cache:eEIuP0aHu8MJ:www.xldynamic.com/source/xld.SUMPRODUCT.html&hl=en&ct=clnk&cd=1&gl=us).

Definitely a very powerful function, SUMPRODUCT, which I had no idea existed, nor just how helpful it can be in situations like the one I detailed above.

Just another fine example of how this is such an AWESOME site!

Thanks again :bow: :clap2: :clap2: :trophy: :trophy: :clap2::clap2::bow:

Bob Phillips
10-29-2008, 01:16 AM
Thank you, Malcolm.

However, being impatient, I found the article cached with Google, here (http://74.125.45.104/search?q=cache:eEIuP0aHu8MJ:www.xldynamic.com/source/xld.SUMPRODUCT.html&hl=en&ct=clnk&cd=1&gl=us).


I didn't know that Google did that, that is useful.