简体   繁体   English

计算列中有多少个值有重复

[英]Count how many values have duplicates in a column

I have values in a column like:我在列中有值,例如:

08FHI800
08FHI800
08FHI800
07FJM933
07FJM933
89MNA900

I need a formula that tells me how many items in the column have corresponding duplicates.我需要一个公式来告诉我列中有多少项具有相应的重复项。 In this case, it would be 2.在这种情况下,它将是 2。

Try this formula assuming data in A2:A100假设 A2:A100 中的数据,试试这个公式

=SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")-(COUNTIF(A2:A100,A2:A100&"")=1))

It will ignore blanks它会忽略空白

=SUMPRODUCT((A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")-(COUNTIF(A1:A12,A1:A12&"")=1))

Using this data as an example使用此数据作为示例

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

Break the function apart into 3 components:将函数分解为 3 个组件:

(A1:A12<>””)

COUNTIF(A1:A12,A1:A12&””)

COUNTIF(A1:A12,A1:A12&””)=1

Component 1组件 1

(A1:A12<>””) evaluates to an array containing {T, T, T, T, T, T, T, T, T, T, T, T} ---------(1)

Component 2组件 2

COUNTIF(A1:A12,A1:A12&””) 

evaluates to评估为

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} 

and it counts the number of times each value appears in the range This in turn evaluates to:并计算每个值出现在范围内的次数 这反过来评估为:

{1,3,3,3,1,1,2,2,3,3,3,1}    -----------------(2)

(the &”” is to avoid #DIV/0 error) (&””是为了避免#DIV/0错误)

Now, because of the brackets we need to evaluate (Component 1 / Component 2) first before looking at Component 3.现在,由于括号的原因,我们需要先评估(组件 1 / 组件 2),然后再查看组件 3。

Component 1/Component 2 is组件 1/组件 2 是

(A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")

So from (1) and (2),所以从(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}

which evaluates to:其评估为:

{1,0.3333,0.3333,0.3333,1,1,0.5,0.5,0.333,0.333,0.333,1}

Now we can look at Component 3现在我们可以看看组件 3

COUNTIF(A1:A12,A1:A12&””)=1

We already have the first bit of this:我们已经有了第一部分:

COUNTIF(A1:A12,A1:A12&””)

from (2), which evaluates to来自(2),其评估为

{1,3,3,3,1,1,2,2,3,3,3,1}  

Combining this with =1 becomes将其与 =1 组合成为

COUNTIF(A1:A12,A1:A12&””)=1

Which in turn evaluates to反过来评估为

{T,F,F,F,T,T,F,F,F,F,F,T}

So, finally combining this all together, we have所以,最后把这一切结合在一起,我们有

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})

Now, T equates to 1 and F equates to 0 so this now becomes:现在,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}

Becomes成为

SUMPRODUCT({0,0.333,0.333,0.333,0,0,0.5,0.5,0.333,0.333,0.333,0}

As there is only one array, SUMPRODUCT simply sums the elements由于只有一个数组,SUMPRODUCT 简单地将元素相加

1+1+1 =3

There are 3 items which are duplicated.有 3 个项目是重复的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM