简体   繁体   English

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

[英]How to count records of Dataset using SSRS report expression

I need to get count of the records of the dataset , where its AsssistTypeId = 1 .我需要计算dataset的记录数,其中AsssistTypeId = 1

My Dateset is something like this,我的日期集是这样的,

+---------+--------+---------------+
| 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             |
+---------+--------+---------------+

Currently I'm get count of the lobbyId distinct value as follows and it's working as expected.according to the above dataset , output for the following expression returns 9目前我得到了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)))

Now I need to get count of the LobbyId where its AsssistTypeId = 1 .现在我需要计算LobbyIdAsssistTypeId = 1 For the above dataset, I'm expecting AsssistTypeId = 1 count as 6 ,How can I write expression for this?对于上述数据集,我期望AsssistTypeId = 1计为6 ,我该如何为此编写表达式?

Updated: 12/8/2020更新日期:2020 年 12 月 8 日

This is what I tried, but it doesn't return any result.这是我尝试过的,但它没有返回任何结果。

=
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         
            )
        )
)

And I also tried this,我也试过这个,

=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))))

This works , but when there have duplicates LobbyId , Its also count that Duplicates, According to the above data set, output shows as, 8 , But its should be 6这行得通,但是当有重复LobbyId时,它也算重复,根据上面的数据集,output 显示为8 ,但它应该是6

This is untested but you could try...这是未经测试的,但您可以尝试...

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

As CountDistinct ignores null (nothing) values, we replace anything that is not the value you want to count with Nothing then do a distinct count of LobbyID from the remaining values.由于 CountDistinct 忽略 null (无)值,我们将任何不是您想要计算的值替换为Nothing然后从剩余值中对 LobbyID 进行不同的计数。

You may have to change or remove the "matrix1_RowGroup3" scope, I just guessed what it might be from you existing expression.您可能必须更改或删除"matrix1_RowGroup3" scope,我只是从您现有的表达式中猜到它可能是什么。 I also assumed AsssistTypeID was a typo and removed an 's'.我还假设 AsssistTypeID 是一个错字并删除了一个“s”。

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

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