Excel Formula for How to calculate first consecutive zeroes in excel?

rohankekatpure1987

New Member
Joined
Oct 28, 2015
Messages
34
My excel workbook consists of data below :

0 0 0 0 1 2 3
0 0 1 2 3 0 1
0 0 0 1 2 0 0
0 0 0 0 0 0 0

I want to calculate number of starting zeroes in each row. So my result for the above row would be:

0 0 0 0 1 2 3 => 4
0 0 1 2 3 0 1 => 2
0 0 0 1 2 0 0 => 3
0 0 0 0 0 0 0 => 7

I'm not concerned about the middle zeroes. What excel formula to use to find the starting zeroes in each row?

Thanks,
RK
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi RK and welcome to the board.

No doubt a slicker way, but:

Excel 2013
ABCDEFGHI
1N 1N2N 3N 4N 5N 6N 7Result
200001234
300123012
400012003
500000007
Sheet1
Cell Formulas
RangeFormula
I2{=MIN(IFERROR(MATCH({1;2;3;4;5;6;7;8;9},A2:H2,0),COLUMNS(A2:G2)+1))-1}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
It works fine without entering it as an array formula, so why bother? What am I missing? It also works without the row of N headings - what are they for?
 
Upvote 0
Hi,

can be done without array formula.
have a look at this:

Book1
ABCDEFGHI
100001234
200123012
300012003
400000007
Sheet2
Cell Formulas
RangeFormula
I1=IF(COUNT(A1:G1)=MATCH(1,A1:G1,1),COUNTIF(A1:G1,0),MATCH(1,A1:G1,1)-1)
I2=IF(COUNT(A2:G2)=MATCH(1,A2:G2,1),COUNTIF(A2:G2,0),MATCH(1,A2:G2,1)-1)
I3=IF(COUNT(A3:G3)=MATCH(1,A3:G3,1),COUNTIF(A3:G3,0),MATCH(1,A3:G3,1)-1)
I4=IF(COUNT(A4:G4)=MATCH(1,A4:G4,1),COUNTIF(A4:G4,0),MATCH(1,A4:G4,1)-1)
 
Upvote 0
Hi

Try entering in 1 in A4. ;-)

Hi,

can be done without array formula.
have a look at this:
ABCDEFGHI

<colgroup><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"]4[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"]2[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]
[TD="align: right"]7[/TD]

</tbody>
Sheet2

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10, bgcolor: #DAE7F5"]I1[/TH]
[TD="align: left"]=IF(COUNT(A1:G1)=MATCH(1,A1:G1,1),COUNTIF(A1:G1,0),MATCH(1,A1:G1,1)-1)[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: #DAE7F5"]I2[/TH]
[TD="align: left"]=IF(COUNT(A2:G2)=MATCH(1,A2:G2,1),COUNTIF(A2:G2,0),MATCH(1,A2:G2,1)-1)[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: #DAE7F5"]I3[/TH]
[TD="align: left"]=IF(COUNT(A3:G3)=MATCH(1,A3:G3,1),COUNTIF(A3:G3,0),MATCH(1,A3:G3,1)-1)[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: #DAE7F5"]I4[/TH]
[TD="align: left"]=IF(COUNT(A4:G4)=MATCH(1,A4:G4,1),COUNTIF(A4:G4,0),MATCH(1,A4:G4,1)-1)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
It works fine without entering it as an array formula, so why bother? What am I missing? It also works without the row of N headings - what are they for?
I used inline array constant {1;2;3;4;5;6;7;8;9}, which is why it works without CSE, but it is inherently still an array formula. But you're right, CSE isn't necessary, it was just me on auto-pilot.

The headers are there purely because I like headers. :)
 
Upvote 0
Thanks for the clarification. I asked only because I understand array formulae to be heavier on the Excel file than non-array formulae, although I may not have that quite right. :-)
 
Upvote 0
Thanks for the clarification. I asked only because I understand array formulae to be heavier on the Excel file than non-array formulae, although I may not have that quite right. :-)
You're welcome. An array formula is a means to an end. If we derive the same result then it doesn't necessarily mean that the array formula will be heavier. It really boils down to a number of factors, such as function choice, logic and volume of evaluations to compute a result. Sometimes an array formula does exactly what a stepped approach would do, but without adding to the grid, without expanding used range and other impacts.

In the case of my formula, sure it is likely heavier. I MATCH the presence of 9 numbers when indeed only 1 or 2 (or none) of those numbers even exist in the evaluation range. Indeed that may be unnecessary. But unless the formula will span a considerable volume of rows, I doubt it will be 'heavy'.

These days I've moved beyond the academic and no longer aim to provide the most effective solution, I tend to just aim to give a suitable practical suggestion. Sometimes though what I come up with is simply the only logic I can muster up at the time. :)
 
Upvote 0
Logic is all I have to work with, having never learnt to use Excel from an academic perspective, that and a large dose of curiosity. ;-)
 
Upvote 0
Well you aroused my curiosity, i.e. curious to know whether or not I can muster something up that works that doesn't do unnecessary evaluations. I'm happy with my latest addition, below, but will happily await one of the formula guru's to come up with something more elegant. :)


Excel 2013
ABCDEFGHI
1N 1N2N 3N 4N 5N 6N 7Result
200001234
300123012
400012003
500000007
Sheet1
Cell Formulas
RangeFormula
I2=IF(SUM(A2:G2),MATCH(SMALL(A2:G2,COUNTIF(A2:G2,0)+1),A2:G2,0)-1,COLUMNS(A2:G2))
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,011
Members
452,374
Latest member
keccles

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