Link to home
Start Free TrialLog in
Avatar of jdhackett
jdhackettFlag for Ireland

asked on

Datacolumn Expression Question

Using Visual Basic 2005.
Have a typed dataset. Want to add a calculated column, that is the sum of the Owing column for each client. The client field is called Ref
Any ideas how I would do this?
Avatar of Sancler
Sancler

If I'm understanding you correctly, I'm not sure you can do this.  At least easily.  

If you add an Expression Column, that is restricted to calculations on the data in the row concerned.  So, if each row has columns for Quantity and Price you can add an Expression Column for Total - Quantity * Price.  Then, on a row which shows a quantity of 2 and a price of 4 the Total column will show 8: if 3 and 6, 18; and so on.

Or you can use DataTable.Compute to get (for example) the sum of amounts in a particular column in all - or some filtered selection - of the rows.  So, that way, if each row contained a Client and a detailed Amount owing, you could use that to find the total owing for a particular client.

But it looks, from your question, as if you are trying to combine the two: that is, get a sum by totalling a particular column in a number of rows, but put that sum in a single row, or repeat it in a number of rows.  If that is really your objective you will, I think, have to make your additional column unbound, and write code (using DataTable.Compute) to calculate a sum for each client and then put the sum relating to each client in each row for that client.

Roger
Avatar of jdhackett

ASKER

Thanks. But what would the formula be for this datatable.compute?
I do want it repeated in each row. So if I had two clients, A and B, I'd like column 3 to be the sum of Owing. So it should look like
A   1   6
A   2   6
A   3   6
B   8   17
B   9   17

6 (1+2+3) being the total amount that A owes, 17 (8+9) being the total amount that B owes
I just can't figure out what the formula should be


ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I want to put that in a report, so the datatable needs to have the calculated field.
So is the best way to loop through the datatable, running that calculation for each row, setting the unbound field to the TotalForClient calculation?
Yes