Sum 3 column values in a DataTable

  • Thread starter Thread starter Codex Twin
  • Start date Start date
C

Codex Twin

I have a DataTable, of which the data looks like the section below:

Month Year Fish DataValue
----------------------------------------------------------------
1 2005 Salmon 578.00
2 2005 Salmon 764.00
3 2005 Salmon 141.00
4 2005 Salmon 301.00
5 2005 Salmon 759.00
6 2005 Salmon 272.00
7 2005 Salmon 845.00
8 2005 Salmon 212.00
9 2005 Salmon 424.00
10 2005 Salmon 229.00
11 2005 Salmon 596.00
12 2005 Salmon 730.00

I want to be able to create a new column called QuarterSum using Expressions
within the existing DataTable which will SUM the DataValue column values for
each row for 3 month groupings.

So the QuarterSum for the Quarter months (1, 2, 3) will be (578.0 + 764.0 +
140.0)
Similarly for QuarterMonths (10, 11, 12) will be (229.0 + 596.0 + 730.0)

So something along the lines:
dt.Columns.Add("QuarterSum", typeof(double), Expression);

What is the syntax to use for the above expression to work this?

Thanks
 
You can't sum sets of rows like that. You can only sum columns. So if you
had columns DataValue1 and DataValue2, you could have a 3rd column that
contains the sum of the first 2.
 
Back
Top