views:

617

answers:

2

Have a matrix report now that has Position, Hours and Wages for a location for a month.
There may be any number of locations...that's why I'm starting with a Matrix report...the user may chose up to 50 locations to view.

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

We would like to get an average by position for that month, like so

                   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

Can't quite figure out how to get this to work in SSRS 2005...

+1  A: 

You could have a calculated field with formula (rs!localtion1Hrs + rs!location2hrs) / 2.

OR

The query used to show the report can have this field as calculated column.

shahkalpesh
just edited the question -- added this -- There may be any number of locations...that's why I'm starting with a Matrix report...the user may chose up to 50 locations to view....
w4ik
what is the SQL behind source data?
shahkalpesh
I guess matrix report should have an option to add additional summary columns. Sorry, its been some time that I worked on SSRS
shahkalpesh
Look at this url - http://msdn.microsoft.com/en-us/library/ms157334.aspx . It tries to add extra columns towards the end to do a summary
shahkalpesh
That's only for SSRS 2008...we're on SSRS 2005...the corresponding article for SSRS 2005 here http://msdn.microsoft.com/en-us/library/ms157334(SQL.90).aspx doesn't have a way to do what's in the SSRS 2008 article...I believe that the only aggregate function available in a SSRS 2005 matrix is the Sum function
w4ik
Could you show the SQL query that is used as the dataset for this report?
shahkalpesh
It's based on a complex view, but it really just boils down to this... select location, position, year, month, totalhours, amount from myPayrollTable. For the dataset for the report, I use a sproc to call the view that has parameters on year, month and location...I pass in a year and a month and multiple locations
w4ik
A: 

Pretty sure I've solved this by using the following as the DataSet for the report and using a matrix in the report layout.

Basically I did what shahkalpesh said above..."The query used to show the report can have this field as calculated column."

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
w4ik
If this is part of a stored proc, you could dump the results of the query into a temp table. And use the temp table to do a UNION for average (instead of running the query with SUM(...) twice).
shahkalpesh
understood...after I getting it working, I'll refactor for performance...thanks for your help....
w4ik