Im wondering I may be asking a simple question, but trying to get a elegant solution. I have a situation where below are the rows
State Label <
Not tested, but this should work.
var newList = list.GroupBy(x=> new {x.State , x.Label })
.Select(x=> new YourClass(x.Key.State, x.Key.Label, x.Sum(x=>x.Value) ))
.ToList();
On solution is using grouping:
var result = from o in listObj
group o by o.State into g
select new ValueLabels()
{
State = g.Key,
Label = g.First().Label,
Value = g.Sum(i => i.Value)
};
try this :
MyListOfComplextData.GroupBy(r => r.state)
.Select(a => new { sum= a.Sum(b => b.code), Name = a.Key})
.ToList()
;