SSRS表中一列中特定十进制值的计数

时间:2018-12-13 18:56:46

标签: reporting-services count expression ssrs-expression

我正试图求和特定年龄段的人。 AgeInYears是一个小数。

我尝试过求和,每次都得到0

=SUM(IIF( Fields!AgeInYears.Value = 15, 1, 0 ) )

如果我进行计数,我会得到68,这仍然不正确

=Count(IIF( Fields!AgeInYears.Value = 15, 1, 0 ) )

我不确定我是否正确地将其与小数进行比较。当我在SQL中使用查询时,然后对数据使用数据透视表,我就能找到答案为47(使用Excel比使用SSRS要好得多)。但是在SSRS中,我只能得到0或68的值。

编辑 我正在通过

在自己的查询中计算AgeInYears
cast(cast(datediff(month, invl.ChildDateOfBirth, fp.enddate) as decimal) / 12 as decimal) as AgeInYears

这可能相关吗?

1 个答案:

答案 0 :(得分:0)

当我尝试计算年龄时,我无法解决SSRS给我的任何问题。

相反,我已将查询更新为

Select
    cast(cast(datediff(month, invl.ChildDateOfBirth, fp.enddate) as decimal) / 12 as decimal) as AgeInYears
From Table
Where
    cast(cast(datediff(month, invl.ChildDateOfBirth, fp.enddate) as decimal) / 12 as decimal) > 13 
and 
    cast(cast(datediff(month, invl.ChildDateOfBirth, fp.enddate) as decimal) / 12 as decimal) as AgeInYears < 19

这可确保我的数据仅包含我想要的年龄(介于14-18之间)。 然后在SSRS表中,我在AgeInYears上创建了一个行组,并做了一个简单的

=Count(Fields!AgeInYears.Value)

在文本框中获取每个年龄的正确计数。