如何使用 MS Access 表达式计算多列中的唯一值,如下所示? 我在 Excel 中使用 Countif 来获取状态列中的“是”计数,现在我想使用 MS Access 表达式来获得相同的结果。
1 回答
0
使用该函数进行行聚合。
检查一下
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;
您也可以以 contionous 形式使用此功能。
在状态文本框中添加这样的控制源或直接使用上述查询并选择控制源作为状态。
=Nz(count_sum([col1];[col2];[col3]);0)
于 2018-06-12T07:08:05.890 回答