[英]How to count distinct values in Excel
You can FILTER
the original data and then count the number of unique instances.您可以
FILTER
原始数据,然后计算唯一实例的数量。
Try =COUNT(UNIQUE(FILTER($A$2:$A$10, $B$2:$B$10=$D2)))
尝试
=COUNT(UNIQUE(FILTER($A$2:$A$10, $B$2:$B$10=$D2)))
Here I assume that the original data is in cells A2:B10, and that the criteria for the filtering is in column D.这里我假设原始数据在单元格 A2:B10 中,过滤条件在 D 列中。
I have updated my answer to work for Office 2007 and mixed @Rory's comment to original post with my OFFSET
part of my previous Office 365 solution.我已经更新了适用于Office 2007 的答案,并将 @Rory 对原始帖子的评论与我以前的 Office 365 解决方案的
OFFSET
部分混合在一起。
Plase the following formula in E2
:在
E2
输入以下公式:
=SUM(1/COUNTIFS(OFFSET($A$3,MATCH(D3,$A$3:$A$12,0)-1,1,COUNTIF($A$3:$A$12,D3),1),OFFSET($A$3,MATCH(D3,$A$3:$A$12,0)-1,1,COUNTIF($A$3:$A$12,D3),1)))
The OFFSET
part provides a list of consecutive rows that feature the Acc No
and belong to the same Br code . OFFSET
部分提供了一个连续行的列表,这些行具有Acc No
并且属于相同的Br 代码。 It uses MATCH
to determine the first occurance of the given Br code .它使用
MATCH
来确定给定Br 代码的第一次出现。 As the anchor cell for the formula is the cell with the first content ( $A$3
), I subtract 1 from the MATCH
result.由于公式的锚单元格是包含第一个内容 (
$A$3
) 的单元格,因此我从MATCH
结果中减去 1。 To determine the height, I use a COUNTIF
statement, that counts how many rows feature the current Br code .为了确定高度,我使用了
COUNTIF
语句,该语句计算当前Br 代码具有多少行。
The cell range provided by OFFSET
is then used as input for @Rory's COUNTIFS
solution. OFFSET
提供的单元格范围然后用作COUNTIFS
的COUNTIFS
解决方案的输入。
The text and non-text (numeric) unique and distinct values in the column are quickly listed separately using VBA macro.使用 VBA 宏快速分别列出列中的文本和非文本(数字)唯一且不同的值。
enter image description here在此处输入图像描述
Sub GetCountDistinctValues()
Dim sayi As Long, rang As Range
With CreateObject("Scripting.Dictionary")
For Each rang In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
If rang <> Empty Then
If Not .Exists(rang.Value) Then
.Add rang.Value, Nothing
If IsNumeric(rang.Value) Then sayi = sayi + 1
End If
End If
Next
Range("C2").Value = .Count - sayi
Range("C3").Value = sayi
End With
End Sub
Source: Find count of unique-distinct values资料来源: 查找唯一不同值的计数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.