Counting the number of rows that meet multiple criteria

D-Angle

New Member
Joined
Aug 24, 2011
Messages
23
Hello all :)

I'm a long-time reader of these boards, they have given me a lot of help and tips in the past and kept me in a job on more than one occasion. :) I'm now stuck on a spreadsheet in which I am trying to analyse a large amount of data using formulas, and none of the suggested solutions I have found seem to work. This is a section of the dataset I am working on, it's a sheet of hourly prices of the FTSE100 Index:

FTSEsheet.jpg


What I would like to do, is count the number of rows that meet the same criteria in multiple cells. For example, I would like to count how many times the index was up at 3pm on a Wednesday, how many times it opened down on a Tuesday etc. I would also like to get more complex results as well, such as how many times the index was, say, up at 3pm when it was down at 10am, which I think would be easier to generate if I could count how many rows met those 2 criteria to start with. Most of my searching suggested DCOUNTA, but nothing seems to give a valid result.

Any suggestions greatly appreciated!
 
Try this too (with the layout of the post #13):

Code:
Use Enter to enter the formula

=SUM(SIGN(MMULT(--($A$1:$D$8=TRUE),ROW(INDIRECT("1:"&COLUMNS($A$1:$D$1))))))

Or this small modification in [COLOR=#0000ff]Aladin's formula [/COLOR]- use Ctrl+Shift+Enter to enter the formula

=SUM(SIGN(MMULT(--($A$1:$D$8=TRUE),TRANSPOSE(COLUMN($A$1:$D$1)))))

Markmzz
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
My formula needs no modification at all, especially not an additional function call. And I would never opt for convoluted, expensive formulas, if I can or when there is an alternative available.
 
Upvote 0
Sorry about that.

Code:
Use Ctrl+Shift+Enter to enter the formula

=SUM(SIGN(MMULT(--($A$1:$D$8=TRUE),TRANSPOSE(COLUMN($A$1:$D$1)))))

Markmzz
 
Upvote 0
Hi guys,

I have been using countif function for a column to find out number of rows which have the text 'Female' or 'Male'. However when I use the excel filter function and then manually highlight to count the total sum of rows which contain the above text the excel gives different numbers. Any reason for this, the only thing I can think of is that my formula is not correct or my data column is missing some text, ( I have been through them and cannot find any empty or different text to male/female.

My formula:=COUNTIF(D2:D580,"Male")

Hope I can once again seek the excel power of you legends. Cheers.

Baseem
 
Upvote 0
Hi guys,

I have been using countif function for a column to find out number of rows which have the text 'Female' or 'Male'. However when I use the excel filter function and then manually highlight to count the total sum of rows which contain the above text the excel gives different numbers. Any reason for this, the only thing I can think of is that my formula is not correct or my data column is missing some text, ( I have been through them and cannot find any empty or different text to male/female.

My formula:=COUNTIF(D2:D580,"Male")

Hope I can once again seek the excel power of you legends. Cheers.

Baseem

If I understand correctly what you want, maybe this can helps:

Code:
=SUMPRODUCT(($D$2:$D$580={"Male","Female"})*SUBTOTAL(3,OFFSET($D$2,ROW($D$2:$D$580)-ROW($D$2),)))

Markmzz
 
Upvote 0
Hi guys,

I have been using countif function for a column to find out number of rows which have the text 'Female' or 'Male'. However when I use the excel filter function and then manually highlight to count the total sum of rows which contain the above text the excel gives different numbers. Any reason for this, the only thing I can think of is that my formula is not correct or my data column is missing some text, ( I have been through them and cannot find any empty or different text to male/female.

My formula:=COUNTIF(D2:D580,"Male")

Hope I can once again seek the excel power of you legends. Cheers.

Baseem

Conditional count under autofilter...
Rich (BB code):
=SUMPRODUCT(
  SUBTOTAL(3,OFFSET(D2,ROW(D2:D580)-ROW(D2),0,1)),
  --(D2:D580="Male"))
If you want to count either male or female at the same time:
Rich (BB code):
=SUMPRODUCT(
  SUBTOTAL(3,OFFSET(D2,ROW(D2:D580)-ROW(D2),0,1)),
  --ISNUMBER(MATCH(D2:D580,{"Male","Female"},0)))
 
Upvote 0
I have a slightly different variation on the same basic question. i am using Excel 2007. What I have is a very large table named "dataset" on one tab and on another I am trying to write a formula to count the number of cells that meet three variables. I want to write a formula that counts the number of cells that have "RM", "STCH" and "Open" in their columns. I know Excel allows me to use column headers and the table name in the formula so I tried to write a COUNTIFS function, I also tried a SUMPRODUCT although I am not as familiar with that one, and I keep getting the answer of 0. for instance in the snapshot below the answer would be 1. Can someone assist me?

Order TypeSiteBacklog Week 1
RMSTCHOpen
CMSTCHOpen
RMWCKCANCELLED
RMSTCH
CMWCKOpen

<tbody>
</tbody>
 
Upvote 0
I have a slightly different variation on the same basic question. i am using Excel 2007. What I have is a very large table named "dataset" on one tab and on another I am trying to write a formula to count the number of cells that meet three variables. I want to write a formula that counts the number of cells that have "RM", "STCH" and "Open" in their columns. I know Excel allows me to use column headers and the table name in the formula so I tried to write a COUNTIFS function, I also tried a SUMPRODUCT although I am not as familiar with that one, and I keep getting the answer of 0. for instance in the snapshot below the answer would be 1. Can someone assist me?

Order Type
Site
Backlog Week 1
RM
STCH
Open
CM
STCH
Open
RM
WCK
CANCELLED
RM
STCH
CM
WCK
Open

<TBODY>
</TBODY>

What are the conditions for the count you want? And what is the result you want to see for the sample you posted?
 
Upvote 0
I have a slightly different variation on the same basic question. i am using Excel 2007. What I have is a very large table named "dataset" on one tab and on another I am trying to write a formula to count the number of cells that meet three variables. I want to write a formula that counts the number of cells that have "RM", "STCH" and "Open" in their columns. I know Excel allows me to use column headers and the table name in the formula so I tried to write a COUNTIFS function, I also tried a SUMPRODUCT although I am not as familiar with that one, and I keep getting the answer of 0. for instance in the snapshot below the answer would be 1. Can someone assist me?

Order TypeSiteBacklog Week 1
RMSTCHOpen
CMSTCHOpen
RMWCKCANCELLED
RMSTCH
CMWCKOpen

<tbody>
</tbody>

Try this:

Code:
=COUNTIFS(Table1[Order Type],"RM",Table1[Site],"STCH",Table1[Backlog Week 1],"Open")

Or

=SUMPRODUCT(-(Table1[Order Type]="RM"),-(Table1[Site]="STCH"),--(Table1[Backlog Week 1]="Open"))*
SUBTOTAL(3,OFFSET(Table1[[#Headers],[Order Type]],ROW(Table1[Order Type])-ROW(Table1[[#Headers],[Order Type]]),))

Markmzz
 
Upvote 0
Thank You! the COUNTIFS formula work a treat! Since i need this to be a formula that can be manipulated by the end user I entered a cell reference instead of "RM and "STCH", locked the sheet down except those two cells and gave the user a drop down option to select from. After troubleshooting against my live data it worked very well, thank you!
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,212
Members
449,214
Latest member
mr_ordinaryboy

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