SSRS中的AVG多个查找表达式(Visual Studio)

时间:2017-02-03 17:04:26

标签: vb.net visual-studio-2012 reporting-services crystal-reports ssrs-2012

如果我有6个人,每个人有2个调查回复。每份调查回复都有10个问题。在我的数据集中,我有一列包含所有问题(1,2,3,4 ......),第二列的所有答案都对应于问题。见下图。

我正在尝试平均分数问题1,2,5和&每个人8个。

我在报告属性中添加了一个VB代码并使用下面的表达式并且能够获得问题1的AVG。是否有办法合并问题2,5的AVG& 8?

=Code.AvgLookup(
  LookupSet(
    Fields!Instructorname.Value & "1. Course achieved?",
    Fields!Instructorname.Value & Fields!Questions.Value,
    Fields!Scores.Value, "DataSet1")
 )

问题&答案布局

enter image description here

1 个答案:

答案 0 :(得分:0)

似乎你的函数只需要一个计算问题。注意LookupSet()返回Object[],尽管在SSRS中没有任何显式方法来连接/联合数组,但使用JOINSPLIT函数有一个技巧:

=Code.AvgLookup(split(
  join(
    LookupSet(Fields!Instructorname.Value & "1. Course achieved?",
      Fields!Instructorname.Value & Fields!Questions.Value,
      Fields!Key.Value,Fields!Code.Value,"DataSet1"),","
  )
  & "," &
  join(
    LookupSet(Fields!Instructorname.Value & "2. Content was easy to understand",
      Fields!Instructorname.Value & Fields!Questions.Value,
      Fields!Key.Value,Fields!Code.Value,"DataSet1"),","
  )
  & "," &
  join(
    LookupSet(Fields!Instructorname.Value & "5. Material was easy to understand",
      Fields!Instructorname.Value & Fields!Questions.Value,
      Fields!Key.Value,Fields!Code.Value,"DataSet1"),","
  )
  & "," &
  ... -> join(lookupset(...) for question 8 and so on.
,","))

尽管有效,但处理报告可能需要更多时间。处理此问题的正确方法应该是创建正确的表结构和关系,以便直接从源中获取报表中所需的数据。

如果有帮助,请告诉我。