How to get data in column based on another column field


#1

Hi all,

I have a problem here, I am trying to add up the total for different department
E.g.
DEPARTMENT WORK HRS SUBTOTAL COST
Department 2 Total 43 78
I have already found the distinct department but how do I incorporate to add in(increment) the work hours for each department?


#2

Try this @saraawq,
Dt.Select("Department='Department2'").CopyToDataTable().Compute("Sum(WORK HRS)", "")

Regards,
Arivu


#3

@saraawq

Declaration
DataTable Variable as dta
Dictionary(Of string, Of string) as Dictionary

Query

Dictionarty=( From p in dta.Select
group p by Department=p.Item("DEPARTMENT") Into GroupA=Group
Select GroupA).ToDictionary(Function(x) x(0)("DEPARTMENT").ToString, Function(x) Convert.ToString(x.Sum(Function(y) Convert.ToDouble(y.Item("Work HR").ToString))))

Now the Key value of the Dictionary will be Department and the Value will be sum of working hours of that particular Department.

So You can get the working Hours of Deepartment1 by Dictionary(Department1).ToString and
Deepartment2 by Dictionary(Department2).ToString
Sou can use the same query with slight modifications of column names for grouping and getting sum of other columns.

Regards,
Mahesh


How to sum the data in excel based on the product?
Total of excel column
Query To Count Number Of Requester For Each Priority Type
#5

@arivu96

Dt.Select(“Department=‘Department2’”).CopyToDataTable().Compute(“Sum(WORK HRS)”, “”)

getting these error while i am trying to sum any help??
Invalid usage of aggregate function Sum() and Type: Object

Thanks in advance