Stumped with what looks like simple problem. I have
var SummaryCollection = (from n in ...long criteria with group by clause)
into g select new
{ MonthYear = g.Key,
Amount = g.Sum(p=>p.Amount)}).OrderBy(p=>p.MonthYear);
}
I now get data that looks like this
Jan2009 $100
Feb2009 $134
... and so on
Finally I have
decimal avgAmount = (from x in SummaryCollection select x.Amount).Average();
I now need to get the average of last N months where N is input in a textbox by the user.
Please advise how to get avg of last N from an ordered collection using Linq. thank you
If you know the number of items in the collection (or use
Count()) you can just skip over the firstCount - Nitems: