访问表达式:计算多列中的唯一值

Access expression: Counting unique values in multiple columns

如何使用 MS Access Expression 计算多个列中的唯一值,如下所示? I used Countif in Excel to get the "Yes" counts in the status column and now I want to use MS Access expression to get the same results.

使用该函数进行行聚合。

检查一下

Public Function count_sum(col1 As String, col2 As String, col3 As String) As Integer


Dim count_yes As Integer

count_yes = 0

If (col1 = "YES") Then
count_yes = count_yes + 1
End If

If (col2 = "YES") Then
count_yes = count_yes + 1
End If

If (col3 = "YES") Then
count_yes = count_yes + 1
End If

count_sum = count_yes

End Function

使用以下查询调用此函数

SELECT col1,col2,col3, count_sum([col1],[col2],[col3]) as Status
FROM Table1;

您也可以在连接形式中使用此功能。

在状态文本框中像这样添加控件源或直接使用上面的查询和select控件源作为状态。

=Nz(count_sum([col1];[col2];[col3]);0)