显示 Reporting Services 矩阵中重叠范围的聚合

发布于 2024-08-07 16:49:21 字数 364 浏览 3 评论 0原文

我在显示矩阵行中一系列日期的值时遇到问题。我希望有一个矩阵显示以下数据:

            Trial Existing  Total
Yesterday      3    1       4
This Week      5    3       8
Last Week     18    5      23
Month to Date 26    9      35
Last Month    32   20      52

我认为解决方案是创建一个计算字段,其中包含取消范围的文本值(“昨天”、“本周”等)。问题在于这些日期范围重叠,并且该字段只能保存一个文本值。

有没有办法在 Reporting Services 中创建这样的矩阵表?

I'm having a problem displaying the values for a range of dates in a matrix row. I would like to have a matrix display the following data:

            Trial Existing  Total
Yesterday      3    1       4
This Week      5    3       8
Last Week     18    5      23
Month to Date 26    9      35
Last Month    32   20      52

I thought the solution would be to create a calculated field with the text values for the cancel range ('Yesterday', 'This Week', etc.). The problem is that those date ranges overlap and the field can only hold one text value.

Is there a way to create a matrix table like this in Reporting Services?

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

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

发布评论

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

评论(1

咋地 2024-08-14 16:49:21

如果我可以建议,为什么不在查询中使用 UNION 创建具有相同数据的 SQL 结果集?

例如

SELECT 'Yesterday' AS When, 
SUM(CASE WHEN Status = 'Trial' Then 1 Else 0 End) AS Trial,
SUM(CASE WHEN Status = 'Other' Then 1 Else 0 End) AS Other
FROM myTable
WHERE TheDate >= givenDate AND TheDate < (givenDate + 1)
GROUP BY When
UNION
SELECT 'This Week' AS When, 
SUM(CASE WHEN Status = 'Trial' Then 1 Else 0 End) AS Trial,
SUM(CASE WHEN Status = 'Other' Then 1 Else 0 End) AS Other
FROM myTable
WHERE TheDate >= (givenDate - 7) AND TheDate < (givenDate + 1)
GROUP BY When

注意:我编写此查询是为了向您提供如何在 SQL 中完成此查询的示例。以免依赖 Reporting Services 来完成该工作。

并且您将不得不做一些杂耍才能使用 tsql 中的 DATE 相关函数来获取“本周”的日期。

总计字段可以是报告中的计算字段。

If I may suggest, why not create a SQL resultset with same data using UNION in the query?

e.g.

SELECT 'Yesterday' AS When, 
SUM(CASE WHEN Status = 'Trial' Then 1 Else 0 End) AS Trial,
SUM(CASE WHEN Status = 'Other' Then 1 Else 0 End) AS Other
FROM myTable
WHERE TheDate >= givenDate AND TheDate < (givenDate + 1)
GROUP BY When
UNION
SELECT 'This Week' AS When, 
SUM(CASE WHEN Status = 'Trial' Then 1 Else 0 End) AS Trial,
SUM(CASE WHEN Status = 'Other' Then 1 Else 0 End) AS Other
FROM myTable
WHERE TheDate >= (givenDate - 7) AND TheDate < (givenDate + 1)
GROUP BY When

Note: I have written this query to give you an example of how it can be done in SQL. So as to not rely on Reporting Services to do the work.

And you will have to do some juggling to get the dates of "This week" using DATE related functions in tsql.

The Total field can be a calculated field in the report.

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