mean, median, mode in SQL Server Reporting Services

后端 未结 3 1412
青春惊慌失措
青春惊慌失措 2020-12-12 04:43

Is it possible to calculate an mean, median, mode, standard deviation, etc. of a column of data?

In general, is it possible to do these sorts of math calculations i

3条回答
  •  轮回少年
    2020-12-12 05:10

    Here is Median() From Report Design Tips and Tricks...

    Scenario 1

    1: In Report Designer, open the Report Properties dialog box and click the Code tab. Define an array, a function that takes a value and adds it to the array, and a function that calculates the median value from the array;

    Dim values As New SystemCollections.ArrayList
    
    Function AddValue(newValue As Decimal) As Decimal
       values.Add(newValue)
       AddValue = newValue
    End Function
    
    Function GetMedian() As Decimal
       Dim count As Integer = values.Count
       If (count > 0)
          values.Sort()
          GetMedian = values(count\2)
       End If
    End Function
    

    2: Wrap the call to the function in an aggregate and add it to an expression in the detail rows.

    =Max(Code.AddValue(Fields!field.Name))
    

    3: From a text box in the table footer, call into GetMedian() to retrieve the value

    =Code.GetMedian()
    

提交回复
热议问题