I want to count how many times 0 occurs twice consecutively. See link at the bottom (blue text).
I've tried: =SUM(IF(FREQUENCY(IF(C7:BA7="0";ROW(C7:BA7));IF(C7:BA7="0";ROW(C7:BA7)))=2;1))
With Ctrl+Shift+Enter, but it is not working correctly.
I want to count how many times 0 occurs twice consecutively. See link at the bottom (blue text).
I've tried: =SUM(IF(FREQUENCY(IF(C7:BA7="0";ROW(C7:BA7));IF(C7:BA7="0";ROW(C7:BA7)))=2;1))
With Ctrl+Shift+Enter, but it is not working correctly.
With the additional information that all distinct, non-overlapping pairs should be counted and non-zero cells may be empty, I would set up a helper row with a formula starting in B4 to count down from zero during each run of zeroes and work out the number of pairs at the end of each run of zeroes:-
=IF(AND(B3=0,LEN(B3)=1),IF(A4<=0,A4-1,-1),IF(A4<0,INT(ABS(A4)/2),0))
Then sum the number of pairs in the row (ignoring any negative numbers) with the following formula in U4:-
=SUMIF(B4:T4,">0")
This works fine to look at columns A to H: {=SUM(IF(A1:H1=B1:I1,1,0))}
. It's an array formula which compares A1
with B1
, then B1
with C1
... H1
with I1
, and adds 1
to the sum if they're the same, or 0
otherwise.
Should work fine. Use Ctrl+Shift+Enter
to make it work as an array formula, and don't type in the {
& }
, obviously.
[This is what i'm working wiht, see link for picture. My problem is that i wanna count the occurrences of how many times two 0 occur in a row. A run of three zeros should not be counted twice.
Context for the problem: is that i wan't to count how many times a product have gone two weeks without a single sale. And as you'll see in the picture no sales are registered with a 0 and sales are just blank. So if Week 1 and Week 2 have a 0, it should count for 1. This way i can tell our external sales force that they need to look into the presentation etc. of this product, because it hasen't sold anything for two tweeks. So anytime two 0 appear continously across the weeks, it should be counted as a single occurence, and then formula should look for the next occurence of two 0 (two weeks without sales). ]1
I will post this as another answer, for which much credit must go to @ambrosen.
So the formula to find each run of two or more zeroes followed by a blank and count the number of occurrences is:-
=SUM(ISNUMBER(B3:S3)*ISNUMBER(C3:T3)*ISBLANK(D3:U3))
must be entered as an array formula using CtrlShiftEnter
So for the first two products in the image:-
With the additional information that all distinct, non-overlapping pairs should be counted and non-zero cells may be empty, a pure array-formula solution is extremely difficult to achieve, but a compromise solution would be to use an existing array-concatenation function like the one here to copy the range into a string, then substitute each pair of zeroes with a single character:-
=LEN(StringConcat("",IF(B3:S3="","/",B3:S3)))
-LEN(SUBSTITUTE(StringConcat("",IF(B3:S3="","/",B3:S3)),"00","0"))
Call this as a function e.g.
=CountPairs(B3:S3)
NB only works for row ranges in present version.
Function CountPairs(rng As Variant) As Integer
Dim v As Variant
Dim count, length, i As Integer
Dim found As Boolean
count = 0
found = False
v = rng
length = UBound(v, 2)
For i = 1 To length
' Count if second of pair
If Not (IsEmpty(v(1, i))) Then
If found Then
count = count + 1
found = False
Else
found = True
End If
Else
found = False
End If
Next i
CountPairs = count
End Function