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 ObservableCollection(Of Product) = DataUtil.Products ' Variables used for intermediate calculations Dim sum As Double = 0 Dim count As Integer = 0 Dim squaredsum As Double = 0 Dim tempVal As Double = 0 For Each item As Product In convertedData ' Value in UnitsInStock column tempVal = Convert.ToDouble(item.UnitsInStock) count = (count + 1) ' Sum values in UnitsInStock column sum = (sum + tempVal) ' Square values in UnitsInStock column squaredsum = (squaredsum _ + (tempVal * tempVal)) Next If ((count < 2) _ OrElse (sum = 0)) Then Return 0 End If ' Calculate average of UnitsInStock column Dim theAverage As Double = (sum / count) ' StandardDeviation formula Dim theDeviation As Double = ((squaredsum _ - (sum * theAverage)) _ / (count - 1)) ' Return standard deviation of UnitsInStock column Return Math.Sqrt(theDeviation) End Function End Class