Showing posts with label Average from datatable. Show all posts
Showing posts with label Average from datatable. Show all posts

Tuesday, June 30, 2009

Find Average from datatable column using LINQ and Compute Method

--Using LINQ

var v = (from o in dt.Rows.Cast()
select o.Field("Grand Total")).Average();

--Using Datatable Compute Method

Object objAvg;
objAvg = dt.Compute("Avg([Grand Total])", "[Grand Total] > 0");

--Find Standard Deviation using Datatable Compute method

Object objStDev;
objStDev = dt.Compute("StDev([Grand Total])", "[Grand Total] > 0");