Search code examples
reporting-servicesssrs-2008reportmedianssrs-expression

Calculating Median - Report Builder 3 - SSRS - "Median=0" - What is wrong with my code?


These are my datasets:

These are my data sets

Average Cost column and expression

Average Cost column and expression

This is my Median column and expression

This is my Median column and expression

Details Group Property variables and expression

Details Group Property variables and expression

Code that I am using to TRY and calculate the median

Code that I am using to TRY and calculate the median

These are the results.

These are the results

The Median is always zero and I would really like to know why. If any further information is needed to try and resolve this please leave a comment and I will do it ASAP.


Solution

  • What if you returned the median in the AddValue function?

    Function AddValue(newValue As Decimal)
        If values Is Nothing Then
            values = New System.Collections.ArrayList
        End If
    
        values.Add(newValue)
    
        Return GetMedian()
    End Function
    

    You could then use AddValue as the expression for the Median column:

    ="Median = " & Code.AddValue(Fields!AvgCost.Value)