繁体   English   中英

如何使用 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不同值的计数,如下所示,它按预期工作。根据上面的dataset ,output 对于以下表达式返回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)))

现在我需要计算LobbyIdAsssistTypeId = 1 对于上述数据集,我期望AsssistTypeId = 1计为6 ,我该如何为此编写表达式?

更新日期:2020 年 12 月 8 日

这是我尝试过的,但它没有返回任何结果。

=
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时,它也算重复,根据上面的数据集,output 显示为8 ,但它应该是6

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

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

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

您可能必须更改或删除"matrix1_RowGroup3" scope,我只是从您现有的表达式中猜到它可能是什么。 我还假设 AsssistTypeID 是一个错字并删除了一个“s”。

暂无
暂无

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

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