## Calculate Median Values in SSRS

 Author Message fliu2265 Mr or Mrs. 500 Group: General Forum Members Points: 571 Visits: 55 Hello,I have the following codes to calculate the median value by groups in SSRS.********************************************Dim Public Shared MedianArray(0) As IntegerPublic Function ResetMedian()ReDim MedianArray(0)End FunctionPublic Function AddToMedian(fieldValue As Decimal) As DecimalDim i As Integeri = UBound(MedianArray) + 1ReDim Preserve MedianArray(i)MedianArray(i) = fieldValueAddToMedian = fieldValueEnd FunctionPublic Function GetMedian() as DecimalDim arraySize as IntegerDim ii as IntegerDim jj As IntegerDim itemMoved As BooleanDim temp As Integer'sort it & calculate itarraySize = UBound(MedianArray)If arraySize = 1 ThenGetMedian = ( MedianArray(0) )Exit FunctionElse If arraySize > 1 ThenFor ii = 0 To arraySize - 1itemMoved = falseFor jj = LBound(MedianArray) To UBound(MedianArray) - 1If MedianArray(jj) > MedianArray(jj + 1)temp = MedianArray(jj)MedianArray(jj) = MedianArray(jj + 1)MedianArray(jj + 1) = tempitemMoved = TrueEnd IfNextIf itemMoved = False Then Exit ForNext'calculate itIf arraySize Mod 2 = 0 Then'average the two middle valuesGetMedian = ( (MedianArray(arraySize / 2) + MedianArray((arraySize / 2) + 1)) / 2) Else'get the middle valueGetMedian = MedianArray(Floor((arraySize / 2)) + 1)End IfEnd IfEnd Function*********************************************************The code is working except a minor problem.For example, I have following salary in the order. \$3112.00 \$3142.50 \$3432.00 \$3475.00 So the median salary should be (3142.50+3432.00) / 2 = 3422.25. However, the result only shows \$3422.00 (no decimal parts), not \$3422.25. But if I test using GetMedian = (100.50+ 100.70)/2 = 100.60. The result shows correctly.Any help is highly appreciated.ThanksFrank Sue_H SSC Guru Group: General Forum Members Points: 77484 Visits: 15517 Try the format property of the cell or text box where you are displaying this value. Refer to this documentation for more information: Formatting Numbers and Dates (Report Builder and SSRS)Sue