google-sheets

how do i count the highest amount of recurring events in a sequence


I am trying to count the amount of negative numbers in a sequence, however, the previous number needs to be negative. The sequence has positive and negative numbers.

my solution so far is as follows

=COUNTIFS(Database!M:M;"<0";Database!M:M;"<>0";indirect("Database!M:M"&ROW()-1);"<0")

to clarify

=COUNTIFS(in Column M:M; count the numbers that are negative;in Column M:M; exclude 0;in Column M:M(Look at the number 1 column above); check if it is lower than 0)

at the end it should give me the amount of the highest sequence but i didn't come that far yet

using this i get the error "Array arguments to COUNTIFS are of different size"


Solution

  • Your reasoning is correct. If you're able to add a computed column, I’d suggest counting the current sequence of consecutive negative numbers. This can be done using an IF statement: if the number is positive, the sequence resets to 0; if it’s negative, the sequence is 1 more than the sequence for the previous number (i.e., the value in the cell above in that column). This can be defined using the following formula (for cell B2; repeat it for the entire column):

    =IF(A2>=0,0,B1+1)
    

    After that you can simple take the maximum of that column =MAX(B:B)

    enter image description here