简体   繁体   English

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

[英]AVG multiple Lookup expression in SSRS (Visual Studio)

If I have 6 people and each person has 2 Survey Responses. 如果我有6个人,每个人有2个调查回复。 Each Survey Responses has 10 questions. 每个调查回复都有10个问题。 On my dataset, I have one column that has all the questions (1, 2, 3, 4.... )and the second column has all the answers correspond to questions. 在我的数据集上,我有一列包含所有问题(1、2、3、4 ...),第二列具有与问题对应的所有答案。 See image below. 参见下图。

I'm trying Average the Scores of Questions 1, 2, 5 & 8 for each person. 我正在尝试为每个人平均问题1、2、5和8的分数。

I've added a VB code in the Report Properties and use the expression below and able to get the AVG for question 1. Is there a way to incorporate the AVG of Question 2, 5 & 8? 我在“报表属性”中添加了VB代码,并使用下面的表达式并能够获取问题1的AVG。是否可以合并问题2、5和8的AVG?

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

Question & Answer Layout 问答布局

在此处输入图片说明

It seems your function takes only one question for the calculation. 看来您的函数只需要计算一个问题。 Note LookupSet() returns a Object[] and despite there is not any explicit method to concatenate/union arrays in SSRS, there is a trick to do so using JOIN and SPLIT functions: 注意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.
,","))

Despite this works, it could take more time to process your report. 尽管这样做有效,但是可能需要更多时间来处理您的报告。 The correct way to handle this should be creating the proper table structures and relationships that lets you get the data you need in your report directly from your source. 解决此问题的正确方法应该是创建适当的表结构和关系,以使您可以直接从源中获取报表中所需的数据。

Let me know if this helps. 让我知道是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM