Counting Number of Consecutive Negative/Positive Numbers in a Row

JAV3784

New Member
Joined
Oct 26, 2014
Messages
6
Office Version
  1. 2021
Hi,

I am analyzing large sets of data and have a column of negative and positive numbers in B2:B784. I am attempting to count how frequently a negative number appears consecutively 1,2,3,4,etc. times in a row and conversely the number of times a positive number occurs 1,2,3,4,etc times in a row. Any ideas how I can accomplish this? Thanks so much.

1720477005319.png
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Could we have a smallish set of dummy sample data and the expected results with XL2BB so that we can see (& copy) exactly the sort of data you are dealing with and how the results should be presented?
(If you have trouble with XL2BB review the "XL2BB Icons greyed out" link in the 'Known XL2BB issues' section near the top of theXL2BB Instructions page linked above.)
 
Upvote 0
Thanks Peter. Having some trouble with the add-in but I'll do my best to describe my scenario here:

- I am analyzing the weekly returns of stocks going back 10 years to see how frequently the stock was down just 1 week before having a positive return, down 2 consecutive weeks before a positive return, etc.. These numbers are all in column B.
- My goal is to count:
-the number of times that a stock was negative just 1 week before being positive the following week
-the number of times that a stock was negative 2 weeks in a row before being positive the following week
-the number of times that a stock was negative 3 weeks in a row before being positive the following week
-etc etc...

Let me know if that is helpful. Thanks again.
 
Upvote 0
Here's something you can start with using helper columns- one for positive and one for negative. There may be a solution without the helpers that will follow.
Book1
BCDEFGH
1datanegative helperpositive helper# consecutivenegative countpositive count
22901157
3-2810222
4805310
54600421
62300501
73500
83200
9-1710
10801
11-3440
12-4800
13-500
14-2900
153901
16-4430
17-1200
18-4100
19301
20-220
21-500
224402
231900
24-510
252904
263200
274200
282800
29-3310
301401
31-510
324301
33-2540
34-2500
35-2000
36-2500
371402
384900
39-1720
40-3100
414801
Sheet8
Cell Formulas
RangeFormula
C2:C41C2=(1-OR(B2>0,N(B1)<0))*(SUM(--(B2:XLOOKUP(FALSE,B2:$B$41<0,B2:$B$41,$B$41)<0)))
D2:D41D2=(1-OR(B2<0,N(B1)>0))*(SUM(--(B2:XLOOKUP(FALSE,B2:$B$41>0,B2:$B$41,$B$41)>0)))
F2:F6F2=SEQUENCE(MAX(C2:D41))
G2:G6G2=COUNTIFS(C2:C41,F2#)
H2:H6H2=COUNTIFS(D2:D41,F2#)
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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