SSRS 2008 组变量 - 对组内的项目进行计数

发布于 2025-01-06 04:14:21 字数 390 浏览 0 评论 0原文

我有一份报告,其中包含代表系统警报的大量统计数据。

我通过拉回用户选择的日期范围内的所有统计数据来制作了一个向下钻取样式的报告,然后我在警报的 codeId 上添加了一个组,这样我就可以对某些内容进行分组。

我想要做的是通过 codeId 计算这些组中的项目数量。我计划将计数用作构成整个组标头的连接字符串的一部分。它基本上是“警报代码# {codeId} - {Description} - 总计:{Total}”。

我的问题是,要在查询中进行计数,我必须在数据到达报告之前对数据进行预先分组。如果我这样做,那么我就没有详细数据来扩展该组。运行摘要和详细数据集有点超出我的能力,但我可能需要考虑一个选项。

所以我希望我可以使用组变量来计算组中包含的项目数。谁能告诉我一套粗略的步骤来尝试实现这一目标?

I have a report which grabs a whole bunch of statistical data that represent system alarms.

I've made a drilldown style report by pulling back all the stats in a user selected date range and then I added a group on my alarm's codeId so I would have something to group on.

What I would like to do is have a count of the number of items within these groups by codeId. I plan to use the count as part of a concatenated string that makes up the whole group header. It basically says "Alarm Code # {codeId} - {Description} - Total: {Total}".

My issue is that to do a count in my query then I have to pre-group the data before it hits the report. And if I do that then I do not have my detail data to expand the group on. And running a summary and a detail dataset is a bit over my head but an option I might have to look into.

So I was hoping I could use a group variable to count the number of items contained within the group. Can anyone tell me a rough set of steps to try to pull that off?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最笨的告白 2025-01-13 04:14:21

似乎在这里使用 Group 变量会使事情变得比需要的更加复杂。

由于您在 SSRS 中已经有一个组,因此您可以使用 CountRows 函数。将此表达式放入占位符中,例如:

="Alarm Code #" & Fields!CodeID.Value
 & " - " & First(Fields!Description)
 & " - Total: " & CountRows()

或者,根据大小,您可以向 SQL 查询添加相关子查询:

SELECT
  CodeID,
  MyField,
  MyOtherField,
  (SELECT COUNT(*) FROM myTable t1 WHERE t1.CodeID = t2.CodeID) AS MyRowCount
FROM
  myTable t2

这不是特别高效的 SQL,因此如果您在数十万行或更多行上运行此查询,我会采用第一种方法。

Seems like using a Group variable here would make this more complicated than it needs to be.

Since you already have a group in SSRS, you can use the CountRows function. Put this expression into a placeholder, for example:

="Alarm Code #" & Fields!CodeID.Value
 & " - " & First(Fields!Description)
 & " - Total: " & CountRows()

Or, depending on size, you can add a correlated subquery to your SQL query:

SELECT
  CodeID,
  MyField,
  MyOtherField,
  (SELECT COUNT(*) FROM myTable t1 WHERE t1.CodeID = t2.CodeID) AS MyRowCount
FROM
  myTable t2

This is not particularly efficient SQL, so if you are running this on hundreds of thousands of rows or more, I'd go with the first approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文