Stephen Forero
asked on
sum property of observable collection
Hi guys,
I am trying to sum a property in my observable collection.
Tried below using LINQ and not working, any idea what I'm doing wrong?
I am trying to sum a property in my observable collection.
Tried below using LINQ and not working, any idea what I'm doing wrong?
var summationResult =
from p in BreakdownClass
select into g
{
previousPos = g.Sum(p => p.tPrevPos),
previousPL = g.Sum(p => p.tPrevPL),
topPos = g.Sum(p => p.tTopTrd),
topPL = g.Sum(p => p.tTopPL),
netPos = g.Sum(p => p.tNetPos),
netPL = g.Sum(p => p.tNetPL)
};
ASKER
that's the catch... I don't want to group by anything... I just want to sum up some properties without grouping
ASKER
something like this..
but does not work
but does not work
var summationResult =
BreakdownClass.Sum(x => x.tPrevPL),
BreakdownClass.Sum(x => x.tPrevPos),
;
Please see my post and how I implemented the code.
Each iteration of the query returns one record so either you group in the query or you iterate through all returned records and sum them up.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yepp... I just figured it out and it was the same as your last post... thanks!!!
Give it a try like this.
Open in new window