Data in Row 2 down and D1=blank (0)

in D2

=IF(C2=0,0,D1+1)