Public Class StandardDeviationCalc Inherits SynchronousSummaryCalculator Public Overrides ReadOnly Property SummaryExecution As SummaryExecution Get Return Infragistics.SummaryExecution.PriorToFilteringAndPaging End Get End Property Public Overrides Function Summarize(ByVal data As IQueryable, ByVal fieldKey As String) As Object Dim convertedData As IQueryable = CType(data,IQueryable) ' 中間計算に使用される変数 Dim sum As Double = 0 Dim count As Integer = 0 Dim squaredsum As Double = 0 Dim tempVal As Double = 0 For Each item As NorthwindServiceReference.Product In convertedData ' UnitsInStock 列の値 tempVal = Convert.ToDouble(item.UnitsInStock) count = (count + 1) ' UnitsInStock 列の合計値 sum = (sum + tempVal) ' UnitsInStock 列の二乗値 squaredsum = (squaredsum _ + (tempVal * tempVal)) Next If ((count < 2) _ OrElse (sum = 0)) Then Return 0 End If ' UnitsInStock 列の平均を計算します Dim theAverage As Double = (sum / count) ' StandardDeviation 式 Dim theDeviation As Double = ((squaredsum _ - (sum * theAverage)) _ / (count - 1)) ' UnitsInStock 列の標準偏差を返します Return Math.Sqrt(theDeviation) End Function End Class