Count # of Sequences in a range

Innsbruck

New Member
Joined
Oct 2, 2013
Messages
15
Hi there,

I have a huge data set (10 units and 5 years data set) that contains for each unit an indicator whether a unit is fully or partially operational or zero if not in operation. I am interested to know the number of blocks (a block is defined as a sequence of fully or partially operational days) and the average operational days within a year.

For the sample data below, Unit 1 has 2 blocks and Unit 2 has 3 blocks. Average Operational days for Unit 1 is (1.5+1.8)/2 = 1.65 days

Is this doable in Excel or Excel VBA ?

Any help in this is much appreciated, thanks in advance.

DateUnit 1Unit 2
1/11/201910
1/12/20190.50.5
1/13/201901
1/14/201900
1/15/201910
1/16/20190.80.2
1/17/201901
1/18/201900
1/19/201901

<tbody>
</tbody>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this:


Excel 2010
ABC
1DateUnit 1Unit 2
21/11/201910
31/12/20190.50.5
41/13/201901
51/14/201900
61/15/201910
71/16/20190.80.2
81/17/201901
91/18/201900
101/19/201901
11
121.651.233333
Sheet3
Cell Formulas
RangeFormula
B12=SUM(B2:B10)/COUNTIF(B2:B10,1)
C12=SUM(C2:C10)/COUNTIF(C2:C10,1)
 
Upvote 0
Try:


Book1
ABCDEFGH
1DateUnit 1Unit 2BlocksAverage Operational Days
21/11/201910Unit 1Unit 2Unit 1Unit 2
31/12/20190.50.5231.651.233333
41/13/201901
51/14/201900
61/15/201910
71/16/20190.80.2
81/17/201901
91/18/201900
101/19/201901
Sheet5
Cell Formulas
RangeFormula
G3=SUM(B:B)/E3
H3=SUM(C:C)/F3
E3{=SUM(SIGN(FREQUENCY(IF(B2:B10>0,ROW(B2:B10)),IF(B2:B10=0,ROW(B2:B10)))))}
F3{=SUM(SIGN(FREQUENCY(IF(C2:C10>0,ROW(C2:C10)),IF(C2:C10=0,ROW(C2:C10)))))}
Press CTRL+SHIFT+ENTER to enter array formulas.


Same basic idea as kweaver, but the formula I use to count the number of blocks doesn't assume that there is exactly one "1" per block.
 
Upvote 0
Try this:

Excel 2010
ABC
1DateUnit 1Unit 2
21/11/201910
31/12/20190.50.5
41/13/201901
51/14/201900
61/15/201910
71/16/20190.80.2
81/17/201901
91/18/201900
101/19/201901
11
121.651.233333

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet3

Worksheet Formulas
CellFormula
B12=SUM(B2:B10)/COUNTIF(B2:B10,1)
C12=SUM(C2:C10)/COUNTIF(C2:C10,1)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Yes it works on the sample data but the case I have it could be a longer sequence of ones then followed by either a value between (0.1 and 0.9) or zero.

I apologize for the confusion :( I have corrected the sample data to account for such cases)


DateUnit 1Unit 2
1/11/201910
1/12/20190.50.5
1/13/201901
1/14/201900
1/15/201910
1/16/201910
1/17/20190.80.2
1/18/201901
1/19/201901

<colgroup><col><col span="2"></colgroup><tbody>
</tbody>
 
Upvote 0
And, what would you expect the averages to be in each case of your new sample?
 
Upvote 0
Try:

ABCDEFGH
1DateUnit 1Unit 2BlocksAverage Operational Days
21/11/201910Unit 1Unit 2Unit 1Unit 2
31/12/20190.50.5231.651.233333
41/13/201901
51/14/201900
61/15/201910
71/16/20190.80.2
81/17/201901
91/18/201900
101/19/201901

<colgroup><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet5

Worksheet Formulas
CellFormula
G3=SUM(B:B)/E3
H3=SUM(C:C)/F3

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
E3{=SUM(SIGN(FREQUENCY(IF(B2:B10>0,ROW(B2:B10)),IF(B2:B10=0,ROW(B2:B10)))))}
F3{=SUM(SIGN(FREQUENCY(IF(C2:C10>0,ROW(C2:C10)),IF(C2:C10=0,ROW(C2:C10)))))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



Same basic idea as kweaver, but the formula I use to count the number of blocks doesn't assume that there is exactly one "1" per block.


Thank you Eric, this works perfectly much appreciated :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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