Reset Row Number

Database

Reset Row Number

Hi, I have the following data and I am trying to find a way to identify the rank of the default event for each account. For example, when Default_Event = 1 it means it is a continuous default. So, per the data, the first default event started in 201001 and lasted till 201002, the second default event started in 201005 and lasted till 201006.

Account  Date         Default_Event 

123        201001            1                    

123        201002            1                     

123        201003            0                    

123        201004            0                      

123        201005            1                   

123        201006            1                   

If I use rows() over partition by Account, order by Date; then it just creates a continuous count as below. What I actually want it to do is create something similar to Default_Event_Number.

Account  Date         Default_Event  Rows()_over_Patition_By  Default_Event_Number (Desired Flag)

123        201001            1                      1                                              1

123        201002            1                      2                                              1

123        201003            0                      ?                                              0

123        201004            0                      ?                                              0

123        201005            1                      3                                              2

123        201006            1                      4                                              2

I thought I could rank it, but seeing as how my Default_Event takes the same value, I'm worried it may just rank it all as 1. How can I reset the row counter when it falls to zero? Can I set a condition such as if previous month is 0 then reset the counter?

I really appreciate the help! Thanks.