Counting the number of instances where criteria are met with a minimum of consecutive rows.

FWE_EXCEL

New Member
Joined
May 5, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm a first-time poster so please excuse any mistakes. I have a problem regarding finding a number value for how often a combination of specific criteria is met.

My data is organized in multiple rows, where each downward cell represents 1 hour. The data for criteria 1 (hs <= 1) is located in the B row, while the data for criteria 2 (tp <=10) is located in the C row.

I need to find how many times Criteria 1 (I4) & 2 (I5) are met in a minimum of 6 (I6) consecutive rows in order to determine how many times a suitable operation window is open.

I have tried to use variations of COUNTIF, IF, SUMPRODUCT, and other functions, but had no success yet.

Thanks in advance!

help_excel.PNG
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
So your column B is a count of the number of waves below the height or is a wave height? Column C is a count or a duration? Are you looking for an Excel formula, a VBA based function, or a VBA Macro?
 
Upvote 0
So your column B is a count of the number of waves below the height or is a wave height? Column C is a count or a duration? Are you looking for an Excel formula, a VBA based function, or a VBA Macro?
Thank you for the reply,

To clarify, column B is a specific wave height (hs) that is recorded on the specific timestamp (column A). Column C is the timeperiod of the wave. Im looking for a Excel Formula if thats possible.
 
Upvote 0
This requires a few more things added to your sheet, but it's not too bad. Also it makes it easily customizable

In the below locations (you can adjust the locations as needed):
G2 is a formula to check if both the wave height and wave period match your requirements (you will need to expand it to every row you are calculating for)
J10 requires your input for the column name where you put the G2 formula
J11 requires your input for the first row in which contains the G2 formula
Those are the only 3 that require you to enter data or expand to keep up with your sheet.


As for the rest, they calculate on their own.
I8 is your desired value
J13 calculates the last row used for the G2 formula (it will update if you change J2)
J14 is the range location of all your G2 formula
J15 is a string representation of what the I8 formula is looking for


Book1.xlsm
ABCDEFGHIJ
1timehstphs_swelltp_swell
21.1.18 12:000.854514.86420
31.1.18 13:000.839814.86420Criteria
41.1.18 14:000.824514.86420Wave Height Max1m
51.1.18 15:000.813214.86420Wave Period Max12s
61.1.18 16:000.805814.86420Duration of Window6hours
71.1.18 17:000.797913.51290
81.1.18 18:000.791313.51290Number of Available Windows2
91.1.18 19:000.757413.51290
101.1.18 20:000.787413.51290ColumnG
111.1.18 21:000.786413.51290Start Row2
121.1.18 22:000.780312.28450
131.1.18 23:000.769812.28450Ending Row75
141.2.18 0:000.753812.28450RangeG2:G75
151.2.18 1:000.737712.28450Search Value0111111
Sheet3
Cell Formulas
RangeFormula
I8I8=(LEN(CONCAT(INDIRECT(J14)))-LEN(SUBSTITUTE(CONCAT(INDIRECT(J14)),J15,"")))/(I6+1)
G2:G15G2=IF(AND(C2<$I$5,B2<$I$4),1,0)
J13J13=LOOKUP(2,1/(INDIRECT(J10&":"&J10)<>""),ROW(INDIRECT(J10&":"&J10)))
J14J14=J10&J11&":"&J10&J13
J15J15="0" & REPT("1",I6)


Hope it helps!
 
Upvote 0
Solution
This requires a few more things added to your sheet, but it's not too bad. Also it makes it easily customizable

In the below locations (you can adjust the locations as needed):
G2 is a formula to check if both the wave height and wave period match your requirements (you will need to expand it to every row you are calculating for)
J10 requires your input for the column name where you put the G2 formula
J11 requires your input for the first row in which contains the G2 formula
Those are the only 3 that require you to enter data or expand to keep up with your sheet.


As for the rest, they calculate on their own.
I8 is your desired value
J13 calculates the last row used for the G2 formula (it will update if you change J2)
J14 is the range location of all your G2 formula
J15 is a string representation of what the I8 formula is looking for


Book1.xlsm
ABCDEFGHIJ
1timehstphs_swelltp_swell
21.1.18 12:000.854514.86420
31.1.18 13:000.839814.86420Criteria
41.1.18 14:000.824514.86420Wave Height Max1m
51.1.18 15:000.813214.86420Wave Period Max12s
61.1.18 16:000.805814.86420Duration of Window6hours
71.1.18 17:000.797913.51290
81.1.18 18:000.791313.51290Number of Available Windows2
91.1.18 19:000.757413.51290
101.1.18 20:000.787413.51290ColumnG
111.1.18 21:000.786413.51290Start Row2
121.1.18 22:000.780312.28450
131.1.18 23:000.769812.28450Ending Row75
141.2.18 0:000.753812.28450RangeG2:G75
151.2.18 1:000.737712.28450Search Value0111111
Sheet3
Cell Formulas
RangeFormula
I8I8=(LEN(CONCAT(INDIRECT(J14)))-LEN(SUBSTITUTE(CONCAT(INDIRECT(J14)),J15,"")))/(I6+1)
G2:G15G2=IF(AND(C2<$I$5,B2<$I$4),1,0)
J13J13=LOOKUP(2,1/(INDIRECT(J10&":"&J10)<>""),ROW(INDIRECT(J10&":"&J10)))
J14J14=J10&J11&":"&J10&J13
J15J15="0" & REPT("1",I6)


Hope it helps!
Thank you so much for the thorough explanation and solution to my problem. If I can get it to work this is exactly what I'm looking for, thank you!!

Unfortunately, I continuously get the formula error when trying the formulas you provided. Are there any settings I should be concerned about? I have tried entering with CSE and enter only as well, however, I can't seem to get around the formula error.

I am relatively new to excel, so thank you for bearing with me.
 
Upvote 0
Unfortunately, I continuously get the formula error when trying the formulas you provided. Are there any settings I should be concerned about?
I have not really looked at your problem or the formulas suggested, but a common issue with what you are describing is that your language version of Excel might normally use semicolons to separate functions arguments whereas the suggestion above use commas.

So, for example, instead of
=IF(AND(C2<$I$5,B2<$I$4),1,0)
you might need
=IF(AND(C2<$I$5;B2<$I$4);1;0)
 
Upvote 0
I have not really looked at your problem or the formulas suggested, but a common issue with what you are describing is that your language version of Excel might normally use semicolons to separate functions arguments whereas the suggestion above use commas.

So, for example, instead of
=IF(AND(C2<$I$5,B2<$I$4),1,0)
you might need
=IF(AND(C2<$I$5;B2<$I$4);1;0)
Hi Peter, and thank you for the reply. This was exactly what was causing the errors. Thank you!

I have marked mackc557's reply as the solution. I wish both of you ha nice weekend! :D
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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