如何使用SSRS报表表达式统计数据集的记录

How to count records of Dataset using SSRS report expression

我需要计算 dataset 的记录数,其中 AsssistTypeId = 1

我的日期集是这样的,

+---------+--------+---------------+
| LobbyID | ProdID | AsssistTypeId |
+---------+--------+---------------+
| 285316  | 160    | 1             |
+---------+--------+---------------+
| 285317  | 161    | 2             |
+---------+--------+---------------+
| 285318  | 159    | 1             |
+---------+--------+---------------+
| 285319  | 160    | 1             |
+---------+--------+---------------+
| 285331  | 160    | 2             |
+---------+--------+---------------+
| 285332  | 160    | 1             |
+---------+--------+---------------+
| 285333  | 161    | 2             |
+---------+--------+---------------+
| 285334  | 160    | 1             |
+---------+--------+---------------+
| 285335  | 160    | 1             |
+---------+--------+---------------+
| 285335  | 161    | 1             |
+---------+--------+---------------+
| 285335  | 163    | 1             |
+---------+--------+---------------+

目前我得到 lobbyId 不同值的计数如下,它的工作方式为 expected.according 到上面的 dataset,以下表达式的输出 return s 9

=iif(inscope("matrix1_RowGroup3"), 
IIF(Count(Fields!LobbyID.Value) = 0, "", Count(Fields!LobbyID.Value)),
iif(inscope("matrix1_AssistedBy"),IIF(CountDistinct(Fields!LobbyID.Value) = 0, "", CountDistinct(Fields!LobbyID.Value)),
CountDistinct(Fields!LobbyID.Value)))

现在我需要计算 LobbyId 的数量,其中 AsssistTypeId = 1。对于上面的数据集,我期望 AsssistTypeId = 1 算作 6 ,我该如何为此编写表达式?

更新时间:12/8/2020

这是我尝试过的方法,但没有 return 任何结果。

=
iif
(

    inscope("matrix1_RowGroup3"),   
        IIF
        (
            Fields!AsssistTypeId.Value = 1,
            IIF
            (
                Count(Fields!LobbyID.Value) = 0, "", Count(Fields!LobbyID.Value)            
            ),
            Nothing         
        ),
        IIF
        (
            inscope("matrix1_AssistedBy"),
            
            IIF
            (
                Fields!AsssistTypeId.Value = 1,
                IIF(CountDistinct(Fields!LobbyID.Value) = 0, "", CountDistinct(Fields!LobbyID.Value)),
                Nothing         
            ),
            IIF
            (
                Fields!AsssistTypeId.Value = 1,
                CountDistinct(Fields!LobbyID.Value),
                Nothing         
            )
        )
)

我也试过了,

=iif(inscope("matrix1_RowGroup3"), 
IIF(Count(Fields!LobbyID.Value) = 0, "", Count(Fields!LobbyID.Value)),
iif(inscope("matrix1_AssistedBy"),IIF(SUM(IIF(Fields!AsssistTypeId.Value = 1,1,0)) = 0, "", SUM(IIF(Fields!AsssistTypeId.Value = 1,1,0))),
SUM(IIF(Fields!AsssistTypeId.Value = 1,1,0))))

这行得通,但是当有重复时LobbyId,它也算重复,根据上面的数据集,输出显示为,8 ,但它应该是 6

这是未经测试的,但您可以试试...

=CountDistinct
    (
      IIF (
           Fields!AssistTypeId.Value = 1
           , Fields!LobbyID.Value
           , Nothing
          ) 
    , "matrix1_RowGroup3"
    )

由于 CountDistinct 忽略 null(无)值,我们用 Nothing 替换任何不是您想要计数的值,然后从剩余值中对 LobbyID 进行不同的计数。

您可能需要更改或删除 "matrix1_RowGroup3" 范围,我只是从您现有的表达式中猜测它可能是什么。我还假设 AsssistTypeID 是错字并删除了 's'.