Formula to count only consecutive numbers which fall between two values?

Rook-Knight

New Member
Joined
Jul 16, 2012
Messages
5
Hi,

I have a data set that consists of 17,280 numbers (values pulled every 5 seconds over a 24 hr period for a water level). The purpose is to monitor the efficiency of a pump. So, the water level begins accumulating (after a pump cycle) and it is 2.0, 2.05, 2.07... all the way to about 4.0, where the pump is triggered to start pumping and pump the water level back down to 2 feet, which is when it will shut off and water will begin accumulating again. This cylces through roughly once per hour (24 cycles).

A perfect formula would be one which works like this: "Begin counting once a cell value is less than the value immediately preceeding it, and continue counting until a cell value is greater than the cell value immediately proceeding it." I want the number of cells counted, not a sum of the values within the cells. Then I need the formula to do that again and again through each cycle, and at the end of the column, post the maximum number of cells it counted for any one cycle (which shows me the longest time that the pump took to reduce the water level back to 2ft - I just multiply it by 5 sec). To further complicate it, I don't want it to count the numbers between 2 and 4 while the level is increasing, just when it is decreasing.

To give an example of a similar formula, there is another pumping system which I am monitoring. This data set simply returns "ON" or "OFF". I have the formula counting the maximum number of consecutive times that "ON" is returned, to ensure the pump does not run too long and burn up. It cycles over 100 times per day. The formula looks like this:

{=MAX(FREQUENCY(IF(V5:V293="OFF",ROW(V5:V293)),IF(V5:V293<>"OFF",ROW(V5:V293))))}

Another formula I have is to monitor a sensor and be sure that it is not going into a static state where it reurns the same readings. So, I have excel count the number of times it returns a consecutive identical reading. It looks like this:

=SUMPRODUCT((ABS(S5:S293-S6:S294)<=0)*(S6:S294<>""))

I have no idea how to approach this one. I have tried modifying those formulas above, but to no avail. I explained the purpose of the formula so that if anyone else has another idea of how I can approach the monitoring of the pump efficiency, they could throw it out there. I need this to work for a 97-2003 version. I can test it in either 97-2003 or 2010. But, it MUST work for a 97-03 version. Any help is greatly appreciated.
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Maybe this

A1:A25
4
3,8
3,7
3
2,8
2,6
2,4
2
2,7
2,9
3,5
4
3,8
3,6
3,3
2,8
2,6
2,4
2,2
2
2,5
2,8
3,5
3,8
4

<tbody>
</tbody>


Regular formula to count consecutive descending values (returns 17 with the data sample)
=SUMPRODUCT(--(A1:A24>A2:A25))+SUMPRODUCT(--(A1:A25=4),--(A2:A26<>""))


Array formula to get the MAX (returns 9 with the data sample)
=MAX(FREQUENCY(IF(A1:A24>A2:A25,ROW(A1:A24)),IF(A1:A24<=A2:A25,ROW(A1:A24))))+1
Ctrl+Shift+Enter

Is it ok?

M.
 
Last edited:
Upvote 0
Marcelo. Almost! That gave me the maximum time between pumping cycles (it counted the ascending numbers... I need it to count the descending numbers). It just needs tweaked ever so slightly.
 
Upvote 0
Sorry, i misread yor post and deleted the previous message.

See the new one (above)

M.
 
Upvote 0
Slight modification... Is there a way that I can also get an average of the decending values? So, for the example given above, it would return (8.5). I tried putting AVERAGE in front instead of MAX, but it returned a number that was an impossible average (1.1153). There are no numbers in the data set that fall below (1.9). Again, any help is greatly appreciated.

This is the current formula that Marcelo gave me to give me exactly what I requested yesterday. Maybe we can build off of that or modify it just slightly... I hope it is that easy.

=MAX(FREQUENCY(IF(Y5:Y17284>Y6:Y17285,ROW(Y5:Y17284)),IF(Y5:Y17284<=Y6:Y17285,ROW(Y5:Y17284))))+1

I tried the following modification, among others, but it did not work:

=AVERAGE(FREQUENCY(IF(Y5:Y17284>Y6:Y17285,ROW(Y5:Y17284)),IF(Y5:Y17284<=Y6:Y17285,ROW(Y5:Y17284))))+1
 
Upvote 0
Slight modification... Is there a way that I can also get an average of the decending values? So, for the example given above, it would return (8.5). I tried putting AVERAGE in front instead of MAX, but it returned a number that was an impossible average (1.1153). There are no numbers in the data set that fall below (1.9). Again, any help is greatly appreciated.

This is the current formula that Marcelo gave me to give me exactly what I requested yesterday. Maybe we can build off of that or modify it just slightly... I hope it is that easy.

=MAX(FREQUENCY(IF(Y5:Y17284>Y6:Y17285,ROW(Y5:Y17284)),IF(Y5:Y17284<=Y6:Y17285,ROW(Y5:Y17284))))+1

I tried the following modification, among others, but it did not work:

=AVERAGE(FREQUENCY(IF(Y5:Y17284>Y6:Y17285,ROW(Y5:Y17284)),IF(Y5:Y17284<=Y6:Y17285,ROW(Y5:Y17284))))+1

Try this

=AVERAGE(IF(FREQUENCY(IF(A1:A24>A2:A25,ROW(A1:A24)),IF(A1:A24<=A2:A25,ROW(A1:A24))),FREQUENCY(IF(A1:A24>A2:A25,ROW(A1:A24)),IF(A1:A24<=A2:A25,ROW(A1:A24)))+1))
Ctrl+Shif+Enter

M.
 
Upvote 0
You are impressive Marcelo! Once again, that worked to perfection... exactly what I needed. I didn't think either request was possible. Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,215,282
Messages
6,124,052
Members
449,139
Latest member
sramesh1024

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