如何获得矩阵中行的平均值

时间:2009-05-28 19:16:51

标签: reporting-services reportingservices-2005

现在有一个矩阵报告 一个月的位置,工时和工资。
可能有任意数量的位置...这就是我开始使用Matrix报告的原因......用户可以选择最多50个位置进行查看。

    
                   Location 1         Location 2
               Total Hrs Amount     Total Hrs Amount
    Position1  441.68    $4,201.46  556.73    $6,103.67

我们希望获得该月份的平均值,如此

                   Location 1         Location 2            Avg
               Total Hrs Amount     Total Hrs Amount       Avg Hrs 
    Position1  441.68    $4,201.46  556.73    $6,103.67    499.20

无法弄清楚如何在SSRS 2005中使用它...

2 个答案:

答案 0 :(得分:1)

您可以使用公式(rs!localtion1Hrs + rs!location2hrs)/ 2计算字段。

OR

用于显示报告的查询可以将此字段作为计算列。

答案 1 :(得分:0)

非常确定我已经通过使用以下内容作为报告的数据集并在报告布局中使用矩阵来解决这个问题。

基本上我做了shahkalpesh上面说的...“用于显示报告的查询可以将此字段作为计算列。”

select 
        'Avg' as LocationID, 
        'Avg' as Description, 
        AccountDesc, 
        @PayrollYear as Year,
        @PayrollMonth as Month,
        avg(s.TotalHrs) as TotalHrs, 
        avg(s.Amount) as Amount from 
(
    select LocationID, 'Avg' as Description, AccountDesc, 
    @PayrollYear as Year, @PayrollMonth as Month,       
    sum(TotalHrs) as TotalHrs,
    sum(Amount) as Amount from vwPayroll
    where LocationID in (select value from dbo.ParmsToList(@PayrollLocIds)) 
    and Year = @PayrollYear and Month = @PayrollMonth
    group by LocationID, AccountDesc, Year, Month
) as s
group by AccountDesc

union all

select 
        LocationID, 
        Description, 
        AccountDesc, 
        Year, 
        Month, 
        Sum(TotalHrs) as TotalHrs, 
        Sum(Amount) as Amount 
from vwPayroll
where LocationID in (select value from dbo.ParmsToList(@PayrollLocIds)) 
and Year = @PayrollYear and Month = @PayrollMonth
group by LocationID, Description, AccountDesc, Year, Month