如何计算SSRS图表中的平均值

时间:2015-10-30 04:37:32

标签: sql sql-server reporting-services charts ssrs-2012

我正在报表生成器中为SSRS构建报表。我的数据看起来像:

Raw Data

我的柱形图按组织分组,系列组分类,6个类别中的每一个都适用于每个组织。

我想添加一个额外的系列,以显示每个组织的所有类别的总体平均值。

任何人都可以建议实现这一目标的方法吗?我是否需要在SSRS中使用新的计算字段,是否应该增强我的SQL查询以在那里完成计算?

我的SQL查询是:

select OrganizationUnitID,Category,AVG(NumericValue) as average
, case 
 when AVG(NumericValue) <= 1 then 0
 when AVG(NumericValue) > 1 and AVG(NumericValue) <= 2 then 50
 when AVG(NumericValue) > 2 and AVG(NumericValue) <= 3 then 75
 when AVG(NumericValue) > 3 then 100 end
 as percentage
from SurveyMetricView
group by OrganizationUnitID,Category
order by OrganizationUnitID

所需的结果是此图表:

End Result Chart

提前感谢任何建议。

2 个答案:

答案 0 :(得分:0)

这是您发布的requeriment的可能解决方案。

将文本框添加到表面,只需将其放在报表中的任何位置即可。

enter image description here

将以下表达式设置为文本框。

=Avg(Fields!percentage.Value, "DataSetName")

将以下表达式添加到系列中。请注意表达式中我引用Textbox49,因为它是我之前添加到报表中的文本框的名称,它包含所有值的平均值。

=ReportItems!Textbox49.Value

enter image description here

更改已添加到Line Chart的系列的图表类型。

enter image description here

它将预览:

enter image description here

  

您可以将文本框的Visibility属性设置为hidden = true   如果您不希望它出现在您的报告中。

让我知道这是否有用

答案 1 :(得分:0)

感谢指点。

最后我做的是使用以下查询创建一个新数据集来计算每个组织的总体平均值,主要是选择不同的组织:

 declare @st_date datetime;
declare @en_date datetime;

set @st_date = (@st_datein);
set @en_date = (@en_datein);

Select Distinct
  SurveyMetricView.OrganizationUnitID,
  Avg(SurveyMetricView.NumericValue) As average,
  Case When Avg(SurveyMetricView.NumericValue) <= 1 Then 0
    When Avg(SurveyMetricView.NumericValue) > 1 And
    Avg(SurveyMetricView.NumericValue) <= 2 Then 50
    When Avg(SurveyMetricView.NumericValue) > 2 And
    Avg(SurveyMetricView.NumericValue) <= 3 Then 75
    When Avg(SurveyMetricView.NumericValue) > 3 Then 100 End As percentage
From
  SurveyMetricView 
where 
  OrganizationUnitID in (@OrganizationUnit)
and ClosedDateTime >= @st_date
        and ClosedDateTime <= @en_date
Group By
  SurveyMetricView.OrganizationUnitID
Order By
  SurveyMetricView.OrganizationUnitID
相关问题