Search code examples
google-sheets

Calculate the number of times groupings of three zeros (0's) appear in a row


I tried using the "Countifs" (Google Measure) ...but, I'm hoping there's a simple(r) way to "Look" 👀 ...at:

  1. rows of zeros (0's) ...and
  2. determine how many times three (3) zeros appear [together]
  3. see Google Sheet - below ⤵️

https://docs.google.com/spreadsheets/d/1BjMWeSzq2D7RjqEtNJs-emNdcv38PdYETsJWZDVfftQ/edit?gid=2100307022#gid=2100307022

Explained:

  • Employee A ...has 4 instances (over 18 weeks)
  • Employee B ...has 2 instances (over 18 weeks)
  • Employee C ...has 6 instances (over 18 weeks)
  • Employee D ...has 4 instances (over 18 weeks)

enter image description here


Solution

  • Here's one approach you may test out:

    =byrow(B2:S,lambda(Σ,if(counta(Σ)=0,,len(regexreplace(regexreplace(join(,Σ),"0{3}","Λ"),"[^Λ]",)))))
    

    enter image description here

    • the formula assumes there will be no blank cells in a given row of 18 weeks

    Modified formula if there's gonna be empty cells:

    =byrow(B2:S,lambda(Σ,if(counta(Σ)=0,,len(regexreplace(regexreplace(join(,switch(Σ,"","x",Σ)),"0{3}","Λ"),"[^Λ]",)))))
    

    enter image description here