Suming consecutive numbers greater than a value

dkm06

New Member
Joined
Mar 29, 2014
Messages
4
Hi all, I m presented a problem that I can describe in this way: In A column of numbers, sum only where the formula registers 5 consecutive numbers that are greater than 2 and tabulate the sum of that sequence in column b next to the last counted number greater than 2 in that sequence, example of set up below. For example if there are only 4 consecutive numbers greater than 2 in a sequence, that sequence is ignored. Thank you for your help,

A
B
0
3
4
3
3
5
321
0
1
4
7
3
5
423

<tbody>
</tbody>

<tbody>
</tbody>
 
Last edited by a moderator:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I think this might help. I know it's not exactly what you sought, but I can't figure out a way to prevent the display of the streak when there is a continuing streak below it, as in Row6-7.


Book1
AB
10 
23
34
43
53
6518
7321
80
91
104
117
123
135
14423
Sheet14
Cell Formulas
RangeFormula
B1=IFERROR(SUM(OFFSET(A1,,,-IF((COUNTA($A$1:A1)-MATCH(1,INDEX(1/($A$1:A1<2),0)))>4,COUNTA($A$1:A1)-MATCH(1,INDEX(1/($A$1:A1<2),0)),0))),"")
 
Last edited:
Upvote 0
With your sample data in A1:A14, this regular formula (copied down) seems to do what you want:
Code:
B1: =IFERROR(IF(AND(COUNTIF(A1:INDEX(A$1:A1,LOOKUP(2,1/(A$1:A1<=2)
,ROW(A$1:A1))+1),">2")>=5,A2<=2)
,SUM(A1:INDEX(A$1:A1,LOOKUP(2,1/(A$1:A1<=2),ROW(A$1:A1))+1)),""),"")

Is that something you can work with?
 
Last edited:
Upvote 0
Hi,

I added a bit to DRSteele's formula in Post #2 to "prevent" showing of the "streak" result, don't know if it's a good idea, credit goes to DRSteele for the original formula:


Book1
AB
10 
23
34
43
53
6518
73
80
91
104
117
123
135
14423
Sheet120
Cell Formulas
RangeFormula
B1=IFERROR(IF(OFFSET(B1,-1,0)="",SUM(OFFSET(A1,,,-IF((COUNTA($A$1:A1)-MATCH(1,INDEX(1/($A$1:A1<2),0)))>4,COUNTA($A$1:A1)-MATCH(1,INDEX(1/($A$1:A1<2),0)),0))),""),"")


Don't know if the SUM should be in Row 6 or 7, OP's description would say 6, but OP's sample shows 7 :confused:

Edit: Nope, won't work, if the 0 (zero) in A8 was replaced by 2 or greater.
 
Last edited:
Upvote 0
Ah, I see how to do my formula to account for continuing streaks. Thanks Ron.

Code:
=IFERROR(SUM(OFFSET(A1,,,-IF(AND(A2<=2,(COUNTA($A$1:A1)-MATCH(1,INDEX(1/($A$1:A1<2),0)))>4),COUNTA($A$1:A1)-MATCH(1,INDEX(1/($A$1:A1<2),0)),0))),"")
 
Upvote 0
Maybe...


A
B
1
0​
2
3​
3
4​
4
3​
5
3​
6
5​
18​
7
3​
21​
8
0​
9
5​
10
4​
11
7​
12
3​
13
5​
24​
14
4​
28​
15

Formula in B5 copied down (gray area)
=IF(COUNTIF(A1:A5,">2")=5,IF(ISNUMBER(B4),B4+A5,SUM(A1:A5)),"")

M.
 
Upvote 0
Comment: I assumed that if more than 5 consecutive items was greater than 2...Add all of them.
I may be wrong (it wouldn't be the first time :| )
 
Upvote 0
I think i misunderstood what are the desired results, that is, to show the sum only at the end of the streak.

Maybe this new version..


A
B
1
0​
2
3​
3
4​
4
3​
5
3​
6
5​
7
3​
21​
8
0​
9
1​
10
4​
11
7​
12
3​
13
5​
14
4​
23​

Formula in B5 copied down
=IF(AND(COUNTIF(A1:A5,">2")=5,A6<=2),SUM(A5:INDEX(A$1:A4,IFERROR(1+LOOKUP(2,1/(A$1:A4<=2),ROW(A$1:A4)-ROW(A$1)+1),1))),"")

M.
 
Upvote 0
It is hard to know what the OP wants given that one of the summed numbers in his original message is wrong. The 21 is the sum of all 6 numbers in the streak whereas the 23 is the sum of the last 5 numbers in the streak consisting of, again, 6 numbers. The way I read the text, I believe the OP only wants to sum the last 5 number in the streak no matter how long the streak is (which means the 21 should have been 18). If I am correct, I am pretty sure this somewhat simple, normally-entered formula placed in cell B5 and copied down should work...

B5: =IF(AND(A5>2,A6<=2,INDEX(A1:A5,ROW($1:$5))>2),SUM(A1:A5),"")
 
Upvote 0
It is hard to know what the OP wants given that one of the summed numbers in his original message is wrong. The 21 is the sum of all 6 numbers in the streak whereas the 23 is the sum of the last 5 numbers in the streak consisting of, again, 6 numbers.

Rick,

The way i understood:
21 is the sum of 6 numbers because in the first sequence all numbers are greater than 2. On the other hand, 23 is the sum of only 5 numbers because 1 is not greater than 2, so it should not be included in the sum.

In other words: the first sequence begins in A2 and has, in fact, 6 numbers greater than 2; the second sequence begins in A10 and has only 5 numbers.

Not sure i'm right :confused:

M.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,193
Members
449,213
Latest member
Kirbito

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