我在如下列中有值:
08FHI800
08FHI800
08FHI800
07FJM933
07FJM933
89MNA900
我需要一个公式来告诉我该列中有多少项具有相应的重复项。在这种情况下,它将是 2。
假设 A2:A100 中的数据,试试这个公式
=SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")-(COUNTIF(A2:A100,A2:A100&"")=1))
它将忽略空格
=SUMPRODUCT((A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")-(COUNTIF(A1:A12,A1:A12&"")=1))
以此数据为例
Row# ColA
1 1
2 2
3 2
4 2
5 3
6 4
7 5
8 5
9 6
10 6
11 6
12 7
将函数分解为 3 个组件:
(A1:A12<>””)
COUNTIF(A1:A12,A1:A12&””)
COUNTIF(A1:A12,A1:A12&””)=1
组件 1
(A1:A12<>””) evaluates to an array containing {T, T, T, T, T, T, T, T, T, T, T, T} ---------(1)
组件 2
COUNTIF(A1:A12,A1:A12&””)
评估为
COUNTIF({1,2,2,2,3,4,5,5,6,6,6,7},{1,2,2,2,3,4,5,5,6,6,6,7}
并计算每个值出现在范围内的次数这反过来计算为:
{1,3,3,3,1,1,2,2,3,3,3,1} -----------------(2)
(&””是为了避免#DIV/0 错误)
现在,由于有括号,我们需要先评估(组件 1 / 组件 2),然后再查看组件 3。
组件 1/组件 2 是
(A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")
所以从(1)和(2),
{T,T,T,T,T,T,T,T,T,T,T,T}/{1,3,3,3,1,1,2,2,3,3,3,1}
评估为:
{1,0.3333,0.3333,0.3333,1,1,0.5,0.5,0.333,0.333,0.333,1}
现在我们可以看看组件 3
COUNTIF(A1:A12,A1:A12&””)=1
我们已经有了第一个:
COUNTIF(A1:A12,A1:A12&””)
从(2),其评估为
{1,3,3,3,1,1,2,2,3,3,3,1}
将其与 =1 结合成为
COUNTIF(A1:A12,A1:A12&””)=1
反过来评估为
{T,F,F,F,T,T,F,F,F,F,F,T}
所以,最后把这一切结合在一起,我们有
SUMPRODUCT({1,0.3333,0.3333,0.3333,1,1,0.5,0.5,0.333,0.333,0.333,1} - {T,F,F,F,T,T,F,F,F,F,F,T})
现在,T 等于 1,F 等于 0,所以现在变成:
SUMPRODUCT({1-1,0.333-0, 0.333-0, 0.333-0,1-1,1-1,0.5-0,0.5-0, 0.333-0, 0.333-0, 0.333-0,1-1}
变成
SUMPRODUCT({0,0.333,0.333,0.333,0,0,0.5,0.5,0.333,0.333,0.333,0}
由于只有一个数组,SUMPRODUCT 只是简单地将元素相加
1+1+1 =3
有 3 个项目重复。