0

如果我有6個人,每個人有2個調查回答。每個調查回答有10個問題。在我的數據集中,我有一列包含所有問題(1,2,3,4 ...),第二列的所有答案都對應問題。見下圖。SSRS中的AVG多重查找表達式(Visual Studio)

我試着平均每個人的問題1,2,5分數的問題。

我在報表屬性中添加了一個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") 
) 

問題&回答佈局

enter image description here

回答

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. 
,",")) 

儘管這樣的作品,它可能需要更多的時間處理您的報告。處理這種情況的正確方法應該是創建適當的表結構和關係,以便直接從源獲取報表中需要的數據。

讓我知道這是否有幫助。

+0

謝謝@Alejandro!有用!這非常有幫助! – Chan

+0

@Chan,不客氣。如果我的答案解決了您的問題,您可以[標記爲正確答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)來積極解決問題。 –

相關問題