MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 18th, 2002, 11:56 PM   #1
John McGraw
Board Regular
 
Join Date: Feb 2002
Posts: 76
Default

A while back, on this board Aladin kindly demonstrated for me how to use sumproduct as a conditional count better and more powerful than countif(). I think I am getting the hang of how it works, but need some further help. I do the following to count where two conditions in two seperate columns are true:

=SUMPRODUCT((A1:A50>5)*(B1:B50>10))

I think what happens is that each array is evaluated, then the two are multiplied. So 1*1 (for true values) would = 1. And 0*0 or 0*1 would = 0. Then they are all added together, to produce a count where ">5" AND ">10" are true. Am I right so far on the mechanisms of how this works?

I am also curious on how I could perform an "or" count in the same fashion. I thought about using:

=SUMPRODUCT((A1:A50>5)+(B1:B50>10))

But the problem is that the 1+1's = 2. Thus giving an incorrect final count.

I tried using countif() and OR(), but I couldnt get it to work. So I am looking to sumproduct() for a solution. Am I looking in the right place?

Thanks for any help!
John McGraw is offline   Reply With Quote
Old Mar 19th, 2002, 12:11 AM   #2
Dave Patton
Board Regular
 
Join Date: Feb 2002
Location: Calgary, Alberta Canada
Posts: 2,065
Default


Are you sure that your SumProduct formula did not work?

A very small example and your exact formula would be useful.
Dave Patton is offline   Reply With Quote
Old Mar 19th, 2002, 12:23 AM   #3
John McGraw
Board Regular
 
Join Date: Feb 2002
Posts: 76
Default

The top SUMPRODUCT() did exactly what I wanted. So, yes it works. But I'm trying to do the same thing, except with "OR" logic, instead of "AND". The multiplication of the 2 arrays produces a 1 when both values are true and a 0 otherwise. (So each row is counted when column A >5, _AND_ column B >10)

What I want, is the two arrays to be evaluated, but to produce a 1 when EITHER
condition is true, not just both.

So column A has 50 rows, column B has 50 rows. Each is full of numbers. I want to count each row that contains a value >5 in column A, _OR_ >10 in column B.

Like I said, I am looking to sumproduct, because this seems impossible with countif().
Maybe its impossible with sumproduct as well.
Thats my question.

I hope I have been clear. Sorry if I havent.

Also, I dont have a real idea for a formula on how to do this... The formula in my above post (the sumproduct with +), is the only thing I could think of trying. It obviously doesnt do the job.



[ This Message was edited by: John McGraw on 2002-03-18 23:32 ]
John McGraw is offline   Reply With Quote
Old Mar 19th, 2002, 12:45 AM   #4
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,319
Default

Quote:
On 2002-03-18 23:23, John McGraw wrote:
The top SUMPRODUCT() did exactly what I wanted. So, yes it works. But I'm trying to do the same thing, except with "OR" logic, instead of "AND". The multiplication of the 2 arrays produces a 1 when both values are true and a 0 otherwise. (So each row is counted when column A >5, _AND_ column B >10)

What I want, is the two arrays to be evaluated, but to produce a 1 when EITHER
condition is true, not just both.

So column A has 50 rows, column B has 50 rows. Each is full of numbers. I want to count each row that contains a value >5 in column A, _OR_ >10 in column B.

Like I said, I am looking to sumproduct, because this seems impossible with countif().
Maybe its impossible with sumproduct as well.
Thats my question.

I hope I have been clear. Sorry if I havent.

Also, I dont have a real idea for a formula on how to do this... The formula in my above post (the sumproduct with +), is the only thing I could think of trying. It obviously doesnt do the job.

[ This Message was edited by: John McGraw on 2002-03-18 23:32 ]
Hi John,

The SUMPRODUCT version would be:

[1]

=SUMPRODUCT(1*((A1:A50>5)+(B1:B50>10)))

However,

[2]

=COUNTIF(A1:A50,">5")+COUNTIF(B1:B50,">10")

will compute the same result.

Aladin
Aladin Akyurek is offline   Reply With Quote
Old Mar 19th, 2002, 01:18 AM   #5
John McGraw
Board Regular
 
Join Date: Feb 2002
Posts: 76
Default

Quote:
On 2002-03-18 23:45, Aladin Akyurek wrote:
Hi John,

The SUMPRODUCT version would be:

[1]

=SUMPRODUCT(1*((A1:A50>5)+(B1:B50>10)))

However,

[2]

=COUNTIF(A1:A50,">5")+COUNTIF(B1:B50,">10")

will compute the same result.

Aladin
Thanks Aladin. But I dont think it works. I'm afraid that maybe I wasnt clear enough. I'm sorry for that.

COL A = {01;06;07;01;08;03;05}
COL B = {01;11;12;01;01;01;03};

I only put 0's before single digits so the values would line up and be easier to compare.

Now, if I count A>5 OR B>10; The answer would be 3. But:

=SUMPRODUCT(1*((A1:A7>5)+(B1:B7>10)))

would produce the answer of 5. It is counting rows with two values true twice, thats not OR logic. The countif() solution does the same thing.

I hope I make sense. If a1>5, and b1>10, I only want to count that row once, not twice. Traditional OR logic.

Thanks much for the help, it is appreciated greatly!

John McGraw is offline   Reply With Quote
Old Mar 19th, 2002, 01:36 AM   #6
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,319
Default

Quote:
On 2002-03-19 00:18, John McGraw wrote:
Quote:
On 2002-03-18 23:45, Aladin Akyurek wrote:
Hi John,

The SUMPRODUCT version would be:

[1]

=SUMPRODUCT(1*((A1:A50>5)+(B1:B50>10)))

However,

[2]

=COUNTIF(A1:A50,">5")+COUNTIF(B1:B50,">10")

will compute the same result.

Aladin
Thanks Aladin. But I dont think it works. I'm afraid that maybe I wasnt clear enough. I'm sorry for that.

COL A = {01;06;07;01;08;03;05}
COL B = {01;11;12;01;01;01;03};

I only put 0's before single digits so the values would line up and be easier to compare.

Now, if I count A>5 OR B>10; The answer would be 3. But:

=SUMPRODUCT(1*((A1:A7>5)+(B1:B7>10)))

would produce the answer of 5. It is counting rows with two values true twice, thats not OR logic. The countif() solution does the same thing.

I hope I make sense. If a1>5, and b1>10, I only want to count that row once, not twice. Traditional OR logic.

Thanks much for the help, it is appreciated greatly!
Yep, you got me there.

Try:

=SUMPRODUCT((1*((A1:A7>5)+(B1:B7>10))))-SUMPRODUCT((A1:A7>5)*(B1:B7>10))

Aladin
Aladin Akyurek is offline   Reply With Quote
Old Mar 19th, 2002, 03:47 AM   #7
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi John

I haven't followed this thread but try this:

Let's say Column A has the Heading "Head1" and B the heading "Head2"

Copy these headings to cells to D1:E1
then in cell D2 put: >5 and cell E2 put: <10

Again copyn the 2 headings, this time to cells F1:G1
then in cell F2 put: >5 and cell G2 put: >10


Now in any cell put:
=SUM(DCOUNT(A1:B8,"Head1",D1:E2),DCOUNT(A1:B8,"Head1",F1:G2))

The database Functions offer a lot of flexibility and can be seen here:
http://www.ozgrid.com/download/default.htm
Download: DFunctionsWithValidation.zip

With a bit of imagination you can make are very user friendly spreadheet that will extract your data from a data table that needs to meet up to 256 Criteria.



_________________
Kind Regards
Dave Hawley
OzGrid Business Applications
Microsoft Excel/VBA Training


[ This Message was edited by: Dave Hawley on 2002-03-19 02:48 ]
Dave Hawley is offline   Reply With Quote
Old Mar 19th, 2002, 06:33 AM   #8
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Dave,

is that any 256 criteria or 256 rows of criteria in the criteria range ?

I assume that if we had, say, 400, we could just split it into 2 seperate D functions ?

*please* say yes !

Chris


edit.... oh, 256 criteria columns in the criteria range, you mean ?

[ This Message was edited by: Chris Davison on 2002-03-19 05:35 ]
Chris Davison is offline   Reply With Quote
Old Mar 19th, 2002, 06:43 PM   #9
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi Chris

Yes I mean 256 columns of table headings and 256 criteria under each. But as you say you could use 2 database functions.


Dave Hawley is offline   Reply With Quote
Old Mar 19th, 2002, 08:47 PM   #10
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

400... man, those are a lot of criteria !
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 06:48 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes