Count number of consecutive values based on criteria