计算一个值连续重复两次的次数

Counting the number of times a value is repeated twice in a row

我想统计0连续出现两次的次数。请参阅底部的 link(蓝色文本)。

我试过: =SUM(IF(频率(IF(C7:BA7="0";ROW(C7:BA7));IF(C7:BA7="0";ROW(C7:BA7)))=2;1))

使用Ctrl+Shift+Enter,但无法正常工作。

This is an image of what im working with. I want to count how many times 0 occurs twice. Context for my problem is; I wanna be able to count the occurrences of how many times a product has not sold anything for two weeks in a row. In the picture 0 stands for zero sales that week, where blanks is registered sales. So if Week 1 and Week 2 has a 0, it should be counted as 1 episode of no sales for two weeks. The formula should then move on to find the next occurence of an two weeks with zero sales. if three 0 occur in row it shouldn't be counted twice just once. But if four 0 occur it should be counted twice. :) Thank you all in advance and merry Christmas.. it's my first post so sorry for the mess...

有了所有不同的、不重叠的对都应该被计算在内并且非零单元格可能为空的附加信息,我将设置一个辅助行,其中的公式从 B4 开始,以便在每个 运行 个零,并计算出每个 运行 个零末尾的对数:-

=IF(AND(B3=0,LEN(B3)=1),IF(A4<=0,A4-1,-1),IF(A4<0,INT(ABS(A4)/2),0))

然后在 U4 中使用以下公式对行中的对数求和(忽略任何负数):-

=SUMIF(B4:T4,">0")

查看 A 到 H 列时效果很好:{=SUM(IF(A1:H1=B1:I1,1,0))}。这是一个数组公式,比较 A1B1,然后 B1C1 ... H1I1,并添加 1 如果它们相同则为总和,否则为 0

应该可以正常工作。使用 Ctrl+Shift+Enter 使其作为数组公式使用,显然不要输入 { & }

[这就是我正在使用的,请参阅 link 的图片。我的问题是我想计算两个 0 连续出现的次数。三个零的 运行 不应该被计算两次。

问题的背景:我不想计算一件产品有多少次两周没有一次销售。正如您将在图片中看到的那样,没有销售记录为 0,销售只是空白。因此,如果第 1 周和第 2 周有一个 0,它应该算作 1。这样我就可以告诉我们的外部销售人员他们需要查看该产品的展示等,因为它已经两周没有售出任何东西.因此,任何时候两个 0 在几周内连续出现,都应计为一次出现,然后公式应寻找下一次出现的两个 0(两周没有销售)。 ]1

我将 post 这作为另一个答案,必须归功于@ambrosen。

所以找到每个 运行 的两个或多个零后跟一个空格并计算出现次数的公式是:-

=SUM(ISNUMBER(B3:S3)*ISNUMBER(C3:T3)*ISBLANK(D3:U3))

必须使用CtrlShiftEnter[=15=作为数组公式输入]

因此对于图片中的前两个产品:-

由于应计算所有不同的、非重叠的对并且非零单元格可能为空的附加信息,纯数组公式解决方案极难实现,但折衷的解决方案是使用现有的数组连接函数,例如 here 将范围复制到字符串中,然后用单个字符替换每对零:-

=LEN(StringConcat("",IF(B3:S3="","/",B3:S3)))
-LEN(SUBSTITUTE(StringConcat("",IF(B3:S3="","/",B3:S3)),"00","0"))

圣诞快乐!

将此作为函数调用,例如

=CountPairs(B3:S3)

NB 仅适用于当前版本中的行范围。

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