I'm getting "Syntax error in aggregate argument..." whenever I compute for the sum of a column

Given:

  1. An array that contains distinct Name Values.
  2. A datatable with 2 String columns: Name values, cost

Problem:
I need to get the sum of the cost column, grouped under the same name value.
The values for the sum for each name value are also stored in another array, so as to match with the Name value array.

My solution:
I used the compute function of the datatable.
Convert.ToInt32(dt.Compute(“SUM(Convert(cost,‘System.Int32’))”,“Name Value= '”& nameArray.(counter).ToString &“'”))

My error:
Assign : Syntax error in aggregate argument: Expecting a single column argument with possible ‘Child’ qualifier

Please help!
:smiley:

Thank you!

@mickeydibs48
Try using this to get sum of column

DT.AsEnumerable.Sum(Function(x) Convert.ToDouble(x(“cost”).ToString.Trim) ).ToString

and where function
DT…AsEnumerable.Where(Function(x) x(“column”).ToString.Trim.Equals(“123”)).Sum(Function(x) Convert.ToDouble(x(“column”).ToString.Trim) ).ToString

4 Likes

Thanks for the reply!
Could you also please show me how the whole code should look like?
Thank you very much!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.