Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / March 2008

Tip: Looking for answers? Try searching our database.

Count cells

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
S Muzumdar - 07 Mar 2008 17:54 GMT
I have a long table which looks something like this....

1  4  7  A
1  6  5  D
2  7  4  C
4  8  2  D
3  2  9  A
2  1  4  F
5  6  7  D
1  2  3  A

I need a query which counts the number of times "A" appears in the 4th
column for every "1" in column 1.  In this case the answer would be 2.
Ron Coderre - 07 Mar 2008 17:59 GMT
Try this:

=SUMPRODUCT(--(A1:A10&D1:D10="1A"))

Is that something you can work with?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

>I
have a long table which looks something like this....

> 1  4  7  A
> 1  6  5  D
[quoted text clipped - 7 lines]
> I need a query which counts the number of times "A" appears in the 4th
> column for every "1" in column 1.  In this case the answer would be 2.
S Muzumdar - 07 Mar 2008 18:16 GMT
Works like a charm.... Thanks.

Quick question - what does the "--" between two parantheses do ?
Ron Coderre - 07 Mar 2008 18:31 GMT
In this formula: =SUMPRODUCT(--(A1:A10&D1:D10="1A"))

this section: (A1:A10&D1:D10="1A")
returns a series of boolean (fancy word for: TRUE/FALSE) values
...which are not numeric to Excel.

When an arithmetic operator (+,-,*,/) is applied to a boolean value,
Excel converts TRUE to 1 and FALSE to 0.

The standard convention is to use
the Double-Minus (--) to convert the values.
It works this way:
TRUE=TRUE
-TRUE = -1
--TRUE = 1

FALSE = FALSE
-FALSE = 0
--FALSE = 0

Now, you could easily use 1*TRUE, but the Dbl-Minus indicates to
knowledgable users that you are forcing a conversion and not
trying to calculate something.

So, In the formula, the TRUE/FALSE values are converted to 1's and 0's
by the "--" and the SUMPRODUCT calculates the total.

Does that help?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

> Works like a charm.... Thanks.
>
> Quick question - what does the "--" between two parantheses do ?
S Muzumdar - 07 Mar 2008 19:32 GMT
Yes, that helps.  Thanks a lot.

> In this formula: =SUMPRODUCT(--(A1:A10&D1:D10="1A"))
>
[quoted text clipped - 35 lines]
> >
> > Quick question - what does the "--" between two parantheses do ?
Bob - 07 Mar 2008 18:36 GMT
=SUM(IF(A1:A8=1,(IF(D1:D8="A",1,0))))

> I have a long table which looks something like this....
>
[quoted text clipped - 9 lines]
> I need a query which counts the number of times "A" appears in the 4th
> column for every "1" in column 1.  In this case the answer would be 2.
Dave Peterson - 07 Mar 2008 19:31 GMT
I'd use:

=sumproduct(--(a1:a10=1),--(d1:d10="A"))

Adjust the ranges to match--but you can't use whole columns (except in xl2007).

=sumproduct() likes to work with numbers.  The -- stuff changes trues and falses
to 1's and 0's.

Bob Phillips explains =sumproduct() in much more detail here:
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

And J.E. McGimpsey has some notes at:
http://mcgimpsey.com/excel/formulae/doubleneg.html

> I have a long table which looks something like this....
>
[quoted text clipped - 9 lines]
> I need a query which counts the number of times "A" appears in the 4th
> column for every "1" in column 1.  In this case the answer would be 2.

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.