Search code examples
excelms-office

Count number of contiguous value sequence in entire row in ms excel


enter image description here

My excelsheet is like above,

I want to count number of contiguous non empty sequence in entire row and result should be in column(L).

For example, from A2:K2 there are total 3 contiguous non empty sequence ,so in column L2 answer should be 3 similar for all other rows.

Please help me to write excel formula to get result in column (L).


Solution

  • frequency:

     =SUMPRODUCT(--(FREQUENCY(IF(INDEX(A2:K2,MATCH(1,A2:K2,0)):INDEX(A2:K2,MATCH(1E+99,A2:K2))=1,COLUMN(INDEX(A2:K2,MATCH(1,A2:K2,0)):INDEX(A2:K2,MATCH(1E+99,A2:K2)))),IF(INDEX(A2:K2,MATCH(1,A2:K2,0)):INDEX(A2:K2,MATCH(1E+99,A2:K2))=1,"",COLUMN(INDEX(A2:K2,MATCH(1,A2:K2,0)):INDEX(A2:K2,MATCH(1E+99,A2:K2)))))>0))
    

    enter image description here

    With Office 365 we can use LET to shorten:

    =LET(x,A2:K2,rng,INDEX(A2:K2,MATCH(1,A2:K2,0)):INDEX(A2:K2,MATCH(1E+99,A2:K2)),SUMPRODUCT(--(FREQUENCY(IF(rng=1,COLUMN(rng)),IF(rng=1,"",COLUMN(rng)))>0)))