2013-04-04 163 views
2

我的報告中存在一個問題。 我有一個矩陣是這樣的計算SSRS中的總和和平均值


     |ID |   
|Question(TEXT)| |Point(Value)| |Calculated(Average)| |Calculated(Satisfaction)%| 
        Summary:   |Average(Average) | |Average(Satisfaction)%| 

這個矩陣是另一組是一個頁組內。

所以,我的問題是在頁面的羣體之一,

的QUESTION_TEXT是空白的,在燕鷗所有的點(值)爲0。

平均按該行正顯示出正確的值但是彙總平均值並不正確,因爲它也在考慮額外的行並計算平均值。

所以,如果所有均線的總和是40和有4個問題(包括空白問題) 平均是10,而不是13.33,因爲它除以4,而不是3

該行由於顯示該查詢,所以我需要更改查詢或有一種方法,我可以在SSRS本身做到這一點。

回答

2

你可以使用一個表達喜歡本作的排除空白問題:

=Avg(IIf(Fields!Question_Text.Value = "" or IsNothing(Fields!Question_Text.Value) 
    , Nothing 
    , Fields!Point_Value.Value)) 

或替代:

評論後
=Sum(Fields!Point_Value.Value) 
/Sum(IIf(Fields!Question_Text.Value = "" or IsNothing(Fields!Question_Text.Value), 0.0, 1.0))'Updated 

編輯:

我添加了表情進入一個報告 - 第一次工作正常,第二次罰款也很小,更新後(見編輯細節)。

我創建了一個測試數據集用下面的查詢:

select Question_Group = 'Group1', Question_Text = 'Q1', Point_Value = 10 
union all select Question_Group = 'Group1', Question_Text = 'Q2', Point_Value = 15 
union all select Question_Group = 'Group1', Question_Text = 'Q3', Point_Value = 15 
union all select Question_Group = 'Group1', Question_Text = '', Point_Value = 0 
union all select Question_Group = 'Group2', Question_Text = 'Q4', Point_Value = 10 
union all select Question_Group = 'Group2', Question_Text = 'Q5', Point_Value = 15 
union all select Question_Group = 'Group2', Question_Text = 'Q6', Point_Value = 15 
union all select Question_Group = 'Group2', Question_Text = null, Point_Value = 0 

我剛剛創建了一個組基於Question_Group並添加兩個表達式的組頁腳。在設計模式

報告:

enter image description here

報告結果基於上述數據集:

enter image description here

+0

上面一個不工作。它給出了一個無窮大值 – 2013-04-04 20:25:25

+0

它適用於我基於示例數據集;請參閱上文。如果它仍然不適合您,並且您需要進一步的幫助,請提供更多關於您的數據集的信息和查詢以填充上述示例中的一些示例數據。 – 2013-04-04 20:58:26

+0

就像你說的那樣順暢......感謝一噸伊恩...... – 2013-04-04 21:39:28