问题
I have a report that I have designed in SSRS 2008. I have a row which has couple of values. This is basically a Survey form where there are Values from 1 to 5 .Some of the values are either Blank or N/A(If they don't answer). But While I calculate Average of the Values it includes that particular value. I think it takes it as 0. So
Average of (4, 5,4,4,5,2,3, ,5) = 3.56 instead of 4.00.
Can You please tell me how I can Calculate Average of the the values without considering Blank values.
Thank you
回答1:
You can add a calculated field to your dataset to filter out the unwanted values. Then you can just use a regular expression to make it more readable. Here's an example of the calculated field expression:
=iif(Fields!Score.Value > 0, Fields!Score.Value, Nothing)
Now you can simply reference =Avg(Fields!FilteredScore.Value)
and it will work as desired.
回答2:
I found the below solution for solving my problem:
=SUM(Fields!Score.Value)/Sum(iif(Fields!Score<>0,1,0))
回答3:
Instead of using inbuilt average function, you need to create your own function to accomplish your task.
Mathematically Average = (sum of all answers)/(count of all answers)
For your case you need to modify the denomination to exclude all blank and N/A values.
New Avg func = (sum of all answers)/((count of all answers)-(count of all answers where it is blank or N/A))
SSRS equivalent:
=SUM(Fields!SurveyAnswer.Value)/
(Count(Fields!SurveyAnswer.Value)-
Count(IIF(Fields!SurveyAnswer="" OR UCASE(Fields!SurveyAnswer)="N/A", 1, **NOTHING**)))
OR
=SUM(Fields!SurveyAnswer.Value)/(Count(Fields!SurveyAnswer.Value)-
SUM(IIF(Fields!SurveyAnswer="" OR UCASE(Fields!SurveyAnswer)="N/A", 1, 0)))
HTH.
来源:https://stackoverflow.com/questions/18005747/average-of-all-values-except-0