【问题标题】:Getting YTD figure in SSRS report with filtered column group on year/month在 SSRS 报告中获取 YTD 数据,并按年/月过滤列组
【发布时间】:2012-10-01 14:21:18
【问题描述】:

我有一个 Reporting Services 报告,其中显示了一堆 KPI 分数。每个 KPI 在报告中都有自己的行,对于每一行,我们显示过去 3 年的 SUM 或 AVG(取决于 KPI 类型)得分,然后是当年每月的 SUM、AVG 或(理想情况下)总 YTD 数字:

KPI                     2009 2010 2011  Jan Feb Mar Apr May etc.
Bagels Eaten (Total)    100   90    70  10  20  9   13  14
Sandwiches (Cumm. YTD)  90    75    86  13  23  46  65  76

我看到的问题是 RunningValue 函数似乎跨行工作,而不是在过滤的列组和构成 Jan、Feb、Mar 列的当前行(每月数据,按年和月分组,按当年过滤)。所以输出与上面不同,而是一个基于行中所有值的相当随机的数字(我确信它不是随机的,它看起来就是这样)。

列组称为“MonthNum”,单元格值的表达式根据源数据中的“AggregationType”值决定应用哪个聚合:

=Switch(Fields!AggregationType.Value="SUM", Sum(Fields!ScoreValue.Value), 
       Fields!AggregationType.Value="AVG", Avg(Fields!ScoreValue.Value), 
       Fields!AggregationType.Value="YTD", 
       RunningValue(Fields!ScoreValue.Value,Sum,"MonthNum"))

非常感谢任何帮助

更新: 这是正在使用的数据集的几行示例(每月得分,每 kpi)(格式有点棘手!)。聚合类型为“YTD”的项目将应用累积 YTD 表达式,其他所有内容均为当月的 SUM:

KpiID   Title   KPIOwner    ScoreValue  YearNum MonthNum    ReportingGroupTitle ScoreType   DisplayOrder    DisplayPrecision    UnitOfMeasure   AggregationType
5   Donuts Served   Donut Manager   35  2007    1   Catering Services   Actual  10020   0   Number  YTD
5   Donuts Served   Donut Manager   42  2007    2   Catering Services   Actual  10020   0   Number  YTD
5   Donuts Served   Donut Manager   86  2007    3   Catering Services   Actual  10020   0   Number  YTD
5   Donuts Served   Donut Manager   14  2007    4   Catering Services   Actual  10020   0   Number  YTD
6   Donuts Cooked   Donut Manager   45  2007    1   Catering Services   Actual  10020   0   Number  SUM
6   Donuts Cooked   Donut Manager   48  2007    2   Catering Services   Actual  10020   0   Number  SUM
6   Donuts Cooked   Donut Manager   93  2007    3   Catering Services   Actual  10020   0   Number  SUM
6   Donuts Cooked   Donut Manager   32  2007    4   Catering Services   Actual  10020   0   Number  SUM
6   Donuts Cooked   Donut Manager   18  2007    5   Catering Services   Actual  10020   0   Number  SUM

【问题讨论】:

  • 你能展示你的数据集的样本(几行)吗?

标签: sql-server reporting-services


【解决方案1】:

根据我对您的问题的理解,我会这样做:

假设当聚合类型 YTD 返回累计总计时,直到(包括)MonthNum。

创建一个矩阵,其中包含两个在 KpiID 上的 a 组和一个在 AggregationType 上的子组,以及两个列组(相邻)一个在年份和一个在月份(在年份组上,创建一个过滤器,这样您就不会包括当前年份,并且在月份组中排除年份不是当前年份的值。

那么您可以对年组和月组使用以下表达式(最后一个将为您提供每年最后一个月的 YTD 值)

=Switch(Fields!AggregationType.Value="SUM", Sum(Fields!ScoreValue.Value), 
       Fields!AggregationType.Value="AVG", Avg(Fields!ScoreValue.Value), 
       Fields!AggregationType.Value="YTD", Last(Fields!ScoreValue.Value))

【讨论】:

  • AggregationType 是最终报告中该 KPI 的请求类型。数据源值是原始月度得分(未汇总)。因此,对于 YTD,报表必须完成计算运行 YTD 总数的工作。
  • 我一直在努力做你想做的事,但我做不到。您是否考虑更改您的查询以使 YTD 值已经是累积值?
  • 您好 Joao,不,我希望报告服务根据需要完成汇总原始数据的工作。我敢打赌,Crystal Reports 的人会自嘲说它应该多么容易。老实说,我希望使用 RunningValue 的表达式能够正常工作。也许我需要一个报告代码级函数来执行聚合和跟踪行号,但我不想要任何复杂的东西。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
相关资源
最近更新 更多