i've got web api , method, returning query:
var query = results in context.questionaireresults results.departuredate >= startdate && results.departuredate <= enddate select new { week = { need method group weeks }, average = results.where(x => x.number).average() } return query.tolist();
i want calculate average each 7 days (that being first week).
example:
average 1 ... day 7 (week 1) average 2 ... day 14 (week 2)
how can that? being given interval of datetimes, filter weeks (not week of year)
try (not tested tables)
var avgresult = context.questionaireresults .where(r => (r.departuredate >= startdate && r.departuredate <= enddate)).tolist() .groupby( g => (decimal.round(g.departuredate.day / 7)+1)) .select( g => new { week = g.key, avg = g.average(n => n.number) });
Comments
Post a Comment