【问题标题】:SSRS get sum on an expression fieldSSRS 获取表达式字段的总和
【发布时间】:2018-05-07 15:20:25
【问题描述】:

假设我有以下数据:

TimeTable
Person  Week   Date        EnterTime ExitTime PeriodDiff
----------------------------------------------------
John    1      01.01.2018  09:15     10:35    1:20
John    1      01.01.2018  10:55     12:23    1:28
John    1      01.01.2018  13:00     17:35    4:35
John    1      02.01.2018  09:00     16:35    7:35
John    2      08.01.2018  09:05     11:40    2:35
John    2      08.01.2018  16:15     19:35    3:20
John    2      09.01.2018  10:50     21:57    11:07

我正在尝试制作一份关于人们每周和每天在公司工作的时间的报告。 所以我正在尝试创建以下报告:

                 +[WeekGroup]                                                  +
                 ---------------------------------------------------------------
                                +[DateGroup]                                   +
                 WeeklyTotal    ------------------------------------------------
Person                          FirstEntry     LastExit      TimeInside   Period
[PersonGroup]    <<Exp3>>       Min[EnterTime] Max[ExitTime] <<Exp1>>     <<Exp2>>   

Exp1 = Max(ExitTime) - Min(EnterTime)
Exp2 = Sum(PeriodDiff)
Exp3 应该是每天的 Sum(Max(ExitTime) - Min(EnterTime))

除 Exp3 外,一切正常。
问题是 Exp3 在 DateGroup 之外,因此最小/最大值是指相关周中的每个值。由于时间上的差距,我也不能使用期间的总和。
如何获得每周计算时间差的总和?含义 sum(Exp1) ?

【问题讨论】:

  • 似乎您不需要数据集中的所有详细数据来创建报告。您可以对查询进行聚合,例如 SELECT Person, Week, Date, Min(EnterTime), Max(ExitTime), SUM(PeriodDiff)...GROUP BY Person, Week, Date
  • @niktrs 我不明白你的意思。问题是每天的最小和最大时间被汇总,我需要他们每周的差异总和。由于实际数据包含超过 1 周和 1 个人,因此在报表中使用单个数据集进行计算成为一个大问题。

标签: reporting-services ssrs-tablix


【解决方案1】:

如果将范围添加到聚合函数,则可以使用以下表达式获取组内或组外的Max()Min()

'Returns the max of the whole DataSet
=Min(Fields!ExitTime.Value), "YourDataSetName") 

 'Returns the max of the group with the name 'YourGroupName'
=Min(Fields!ExitTime.Value), "YourGroupName")

您还可以做的是,使用以下表达式尊重您的第一个表达式Expr1()(假设第一个表达式在Textbox1):

=Sum(ReportItems!Textbox1.Value)

【讨论】:

  • 示例简化,需要每周计算每人每周的数据。 Max of DataSet 只会返回 1 个人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多