SSRS Aggregating Aggregates

时光总嘲笑我的痴心妄想 提交于 2019-12-11 02:27:33

问题


I have been banging my head against a wall for the better part of two days now...

My scenario is this:

I have a recordset I have divvied up into 4 groups in an SSRS table. They are:

StartPeriod 
  --> Area
     --> Job#
        --> Details

The column in question is one that contains two different record counts. One is the # of records with an error, and the other is the total number of records for this group (so that I can run a percentage).

For example:

At the details level I might have an item with 4 errors, and an item with 6 and there are a total of 20 records. This means that the total # of records is repeating, which means I cannot sum this number or I will double count my total # of records.

StartPeriod - Area - Job# - Item  - Errors - totalRecords
 January    - 123  - Job3 - item1 -   4    -     20
 January    - 123  - Job3 - item2 -   6    -     20

I can get around this at the Job# level because I can simply say Max(num_records) to get the correct number....however if I want to aggregate up to the Area level (or above) I can't get things to work. I can't do SUM( Max(num_records) ) because that makes no sense, and however I arrange the query in SQL it doesn't add up either.

I feel like this is a fairly common problem, so I am not sure why I am having so much trouble. Any ideas how I can solve this? I hope I am explaining myself clearly.

PS. I am using SSRS 2008R2


回答1:


Make better use of groups, the data already exists in your query.

CountRows("Details")
Sum(Errors, "Details")

This is assuming the group you've created at the details level is called "Details".




回答2:


Try something like this for your query:

declare @totcount int
select @totcount = sum(errors) from your_table
select errors, errors/@totcount as [% of total] from your_table 

as for the area:

declare @totcount int
select @totcount = sum(errors) from your_table
select area, sum(errors)/@totcount as [% of total] 
from your_table 
group by area


来源:https://stackoverflow.com/questions/17954789/ssrs-aggregating-aggregates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!