If your DateFormat
is always be going to like Jan-14 Feb-14 Mar-14 Apr-14 May-14 Jun-14
then you can try to use the ParseExact
to convert it to the DateTime
and then apply the SUM
on it to get the result you want.
var result = dataList.Where(x => DateTime.ParseExact(x.monthName, "MMM-yy", CultureInfo.InvariantCulture) > DateTime.ParseExact("Mar-15", "MMM-yy", CultureInfo.InvariantCulture))
.Sum(x => x.Amount);
In above case it will give the sum
of all amounts which has date greater than Mar-15
.
UPDATE
To add the Group BY
you can simply add as,
.GroupBy(x=>x.Id).Select(x=> new { Person = x.Key,TotalAmount = x.Sum(x=>x.Amount)})
6
solved Iterate through Month name