Reporting services 从记录集中添加按ID分组的第一个值;报表生成器3.0
我返回了一个数据集,该数据集具有不同“目标”的月度值。目标具有唯一ID,目标的月度/日期值将始终相同。不同之处在于,有时一个目标与另一个目标在同一个月内没有值,因为它可能会在以后的某个日期开始,我希望“整合”结果,并根据每个目标的“第一个”起始平衡将其相加。示例数据集为:Reporting services 从记录集中添加按ID分组的第一个值;报表生成器3.0,reporting-services,sum,aggregate-functions,reportbuilder3.0,Reporting Services,Sum,Aggregate Functions,Reportbuilder3.0,我返回了一个数据集,该数据集具有不同“目标”的月度值。目标具有唯一ID,目标的月度/日期值将始终相同。不同之处在于,有时一个目标与另一个目标在同一个月内没有值,因为它可能会在以后的某个日期开始,我希望“整合”结果,并根据每个目标的“第一个”起始平衡将其相加。示例数据集为: goalID monthDate startBalance 1 1/1/2014 10 1 2/1/2014 15 1 3/1/2014 22
goalID monthDate startBalance
1 1/1/2014 10
1 2/1/2014 15
1 3/1/2014 22
1 4/1/2014 30
2 4/1/2014 13
2 5/1/2014 29
我要做的是,根据每个目标的“第一个”最早月/年值,在表格中显示这些合并汇总值。结果会是这样的
Year startBalance
2014 23
这是因为goalID为1的“First”值是10,goalID为2的“First”值是13,但是当我尝试按
Year(Fields!MonthDate.Value)
并使用该表达式
Sum(First(Fields!startBalance.Value))
我收到错误
textrun“StartingValue3.段落[0].TextRuns[0]”的值表达式在外部聚合中使用第一个、最后一个或上一个聚合。不能将这些聚合函数指定为嵌套聚合
是否有人知道我的分组是否不正确,或者是否有其他方法可以将进球的“第一”值正确相加?您必须进行更改
Sum(First(Fields!startBalance.Value))
到
这正是您想要的代码: 抄袭
我不想对整个列求和,我只想对每个ID的当年最早的值求和,就像我上面解释的那样
Sum(Fields!startBalance.Value)
create table #temp
(id int,
monthDate date,
value int)
insert into #temp values(1,'1/1/2014',10)
insert into #temp values(1,'1/2/2014',15)
insert into #temp values(1,'1/3/2014',20)
insert into #temp values(2,'1/4/2014',25)
insert into #temp values(2,'1/5/2014',19)
declare @min int,@max int
select @min=MIN(ID) from #temp
select @max=MAX(ID) from #temp
select * from #temp --This is your main table
select top 0 * into #res
from #temp
while(@min<=@max)
begin
declare @minDT date
set @minDT=(select MIN(MonthDate) from #temp where id=@min)
insert into #res
select *
from #temp
where ID=@min
and Convert(Date,monthDate,103)=Convert(Date,@minDT,103)
set @min=@min+1
end
select * from #res --This is Result
drop table #res
drop table #temp