COUNTA with a condition in another column?

Big Monkey

Active Member
Joined
Nov 5, 2005
Messages
255
OK I've run into a booger here.

I have a simple formula now like

=COUNTA(A2:A65536)

What I want to do is get the same result, but only of column I on the same row contains "mytext"

So:

Col A
1
1
1
1

This would equal to 4 with my formula.

Col A Col B
1 mytext
1
1 mytext
1

How would I write the formula for the above to give me a value of 2?

I tried using a sumproduct, but that is totaling the numbers in column A, and I only want the counta values.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Well for one I've never used pivot tables and I have a project due soon. I'm not sure if I have time to learn a new function and change the entire layout of this spreadsheet in a few days.
 
Upvote 0
Awesome!

Thanks harry.

Question though...

=SUMPRODUCT(--(C2:C65536),--(I2:I65536=O18))

=SUMPRODUCT(--(C2:C65536<>""),--(I2:I65536=O18))

Why does the first formula sum up the values in the range, and the second formula only counts the non blank cells in that same range?

If I didn't see it work, I would think that the second formula is asking Excel to sum the values in the range if the cell is not blank. I'm glad it works, but I don't understand the logic.
 
Upvote 0
You need to understand how SUMPRODUCT works. In this formula

=SUMPRODUCT(--(C2:C6<>""),--(I2:I6=O18))

the (C2:C6<>"") part returns an array of TRUE/FALSE values, e.g.

{TRUE;TRUE;TRUE;FALSE}

the -- then "co-erces" this to 1/0 values, e.g.

{1;1;1;0}

SUMPRODUCT then multiplies the arrays and sums them, effectively giving you a count of rows where column I contains O18 and column C is not blank.

If you only have numbers in column C then in this formula

=SUMPRODUCT(--(C2:C65536),--(I2:I65536=O18))

the first -- is unnecessary because you already have numbers in column C so it could be

=SUMPRODUCT(C2:C65536,--(I2:I65536=O18))

To sum column C when column I is O18, although that can be more easily achieved with

=SUMIF(I:I,O18,C:C)
 
Upvote 0
OK. This formula below gives me an average I'm looking for and it works perfect

=SUMPRODUCT(C2:C65536,--(I2:I65536=O18))/SUMPRODUCT(--(C2:C65536<>""),--(I2:I65536=O18))

I am using this same formula for 5 different columns(switch column C with D, E, F, and G)

Now I want to get the average for all columns combined, C:G. I tried to change it to

=SUMPRODUCT(C2:G65536,--(I2:I65536=O18))/SUMPRODUCT(--(C2:G65536<>""),--(I2:I65536=O18))

but it gives me an error?

I tried to use the trace option to see if I can find out where the mistake was and it froze my PC :LOL:

Help? =]
 
Upvote 0
Try

=AVERAGE(IF(I2:I65536=O18,IF(C2:G65536,C2:G65536)))

confirmed with CTRL+SHIFT+ENTER

edit: amended formula

note: you can do it the way you're attempting, although I don't recommend it, but you need to change the syntax slightly

=SUMPRODUCT((C2:G65536)*(I2:I65536=O18))/SUMPRODUCT((C2:G65536<>"")*(I2:I65536=O18))
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top