Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perform calcs on datatable based on date column

Status
Not open for further replies.

tekkerguy

Programmer
Nov 16, 2005
196
US
I have a datatable which I created by importing a csv file into the datatable. I want to do calculations on the table based on Date. for example, create a new field that has the average of a column, by date. How should/can I do this?

i.e.

the final product of an example would be

Date | amount | Average of amount by date
---------------------------------------------------
Date1 25 25
Date2 3 4.5
Date2 6 4.5
Date3 5 9
Date3 10 9
Date3 12 9

Where the column Average of amount by date is a new column.

 
Hi,

Such columns are called computed/expression columns, and is possible to add one in a DataTable. Read on MSDN for DataColumn.Expression property. But how to make one for your need, depends on how you intend to compute for the column average; the part I kinda don't quite follow. But I believe this should give you a hint.

Btw, there is a limited set of aggregate functions available for column expressions and if you need to use more advanced methods especially for computing date, you may need to revert to updating that column via code thru a rowupdating event.

hope this helps [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top