Question

I've been asked to create a report grouped by values in multiple columns on a single row from a SQL database. For example

Employee Name | Type1Column1 | Type1Column2 | Type2Column1 | Type2Column2
John Doe      | 0.00         | 10.00        | 20.00        | 20.00

Report Output

Name          | Type      | Total
John Doe      | Type1     | 10.00
              | Type2     | 40.00

I hope you get the idea and no i did'nt design the table and no i can't change it but i might be able to tweak the stored procedure which produces the output...

I played around with a few ideas but I'm at a loss; I feel like need some sort of calculated something to group against but i've never come up against this before as i've always designed the datawarehouse and cube myself.

Does anyone have any idea how i could achieve this in SSRS 2008R2 ?

Thanks in advance.

Was it helpful?

Solution

Can you apply the UNPIVOT operator to the query returning that output?

select
EmployeeName, 
case
    when Type like 'Type1%'
    then 'Type1'
    else 'Type2'
end TypeCol,
Total 
from (select EmployeeName, Type1Column1, Type1Column2, Type2Column1, Type2Column2
     from storedprocdata ) as f
unpivot (Total for Type in (Type1Column1, Type1Column2, Type2Column1, Type2Column2)
) as u

Note that the derived table f is grabbing data from a table called storedprocdata. Also the case statement in the main select statement allows grouping the columns you have explicitly by the different types you want.

You can then do an aggregate sum on the Total column within your SSRS report.

OTHER TIPS

The unpivot operator should be more flexible, but (expanding on Jamie F's comment on the question) it would be possible to do this by setting up 5 detail rows (one for each type) and setting the expression for the Total column to be like:

=Fields!Type1Column1.Value+ Fields!Type1Column2.Value+ Fields!Type1Column3.Value+
 Fields!Type1Column4.Value+ Fields!Type1Column5.Value+ Fields!Type1Column6.Value+
 Fields!Type1Column7.Value

- for the Type 1 detail row, with similar expressions for each of the subsequent Type detail rows.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top