I need to get the sum of employees scores for each department using linq.
I only need scores from departments that have more than 20 employees but
not sure Where to put the Where clause also not sure if the query below is correct

var departmentquery = from row in dt.AsEnumerable() group row by row["department"] into grp select new { Sum = grp.Sum(r => r.Field<decimal>("score"); };

Can you give me some more information please. What exactly do you want to retrieve ?

this query will give you all the departments, and for each department the sum. There need to be more than (in this example) 1 employee

var departmentquery = from row in dt.AsEnumerable()
group row by row["department"] into grp
where grp.Count() > 1
select new {
deparmtent = grp.Key,
Sum = grp.Sum(r => r.Field<decimal>("score"))
};

>> Is because the datatype in my database is int and I’m using <decimal>?

Try it to do it with integer than

Sum = grp.Sum(r => r.Field<integer>("score"))

0

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

>> I need my counts to be a percentage of the total score

The query I provided just gives the total for that department...

I'm not sure if you can retrieve it in one query.... I'll take a look

Int16 sumTotal = (Int16)dt.AsEnumerable().Sum(x => x.Field<Int16>("score")); var departmentquery = from row in dt.AsEnumerable() group row by row["department"] into grp where grp.Count() > 1 select new { deparmtent = grp.Key, Sum = grp.Sum(r => r.Field<Int16>("score")), sumTotal, };

Int16 sumTotal = (Int16)dt.AsEnumerable().Sum(x => x.Field<Int16>("score")); var departmentquery = from row in dt.AsEnumerable() group row by row["department"] into grp where grp.Count() > 1 select new { deparmtent = grp.Key, Sum = grp.Sum(r => r.Field<Int16>("score")), Percentage = 100 * (decimal)grp.Sum(r => r.Field<Int16>("score")) / (decimal)sumTotal, };

var departmentquery = from row in dt.AsEnumerable()
group row by row["department"] into grp
where grp.Count() > 1
select new
{
deparmtent = grp.Key,
Sum = grp.Sum(r => r.Field<Int16>("score")),
Percentage = 100 * (decimal)grp.Sum(r => r.Field<Int16>("score")) / (decimal)sumTotal,
Average = grp.Average(r => r.Field<Int16>("score"))
};

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…

Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…