Calculating lengths of trends

incblue

New Member
Joined
Feb 23, 2011
Messages
8
Hi guys, I am completely stumped on this problem. Could anyone help me please?

I am in need of 2 formulae that concern streaks, or trends, of 1s and 0s.
My data is a single column of just 1s or 0s.
For this data, there are two columns that I would like to calculate:

1st column: Rank in trend
If the data cell is the 1st number in the streak, display 1.
If the data cell is the 2nd number in the streak, display 2.
etc etc
The numbers increase until the pattern is broken and a new streak starts, and this column goes back to 1 again.

2nd column: Length of trend
At the start of every streak this column displays how long the streak is.
All cells which are not at the start of a streak should stay blank.

Example Screenshot: (My actual data goes from A1:A40000)
captureqz.png


Solutions using standard formulae instead of VBA are preferred in this case.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi & welcome to the Board, incblue!

Formula of B2:
=IF(A2=A1,SUM(B1,1),1)

Formula of C2:
=IF(B2=1,IF(B2>=B3,1,INDEX(B2:$B$11,MATCH(1,B3:$B$11,-1))),"")

Copy B2:C2 down
 
Upvote 0
ZVI

should second formula not read

=IF(B2=1,IF(B2>=B3,1,INDEX(B2:$B$40000,MATCH(1,B3:$B$40000,-1))),"")
 
Upvote 0
The updated formula for C2:
=IF(B2=1,IF(B2>=B3,1,MATCH(1,B3:$B$40000,-1)+ISNA(MATCH(1,B3:$B$40000,0))),"")
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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