Solved

# Datacolumn Expression Question

Posted on 2008-02-08
Medium Priority
205 Views
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?
0
Question by:jdhackett
• 3
• 2

LVL 34

Expert Comment

ID: 20852374
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
0

LVL 1

Author Comment

ID: 20865114
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

0

LVL 34

Accepted Solution

Sancler earned 2000 total points
ID: 20865195
Something like

Dim TotalForClient As Double = myTable.Compute("SUM(Owing)", "Client = 'A'")

The first argument is the calculation, the second argument is the filter.  The datatype of TotalForClient should be that of the Owing column.

Roger
0

LVL 1

Author Comment

ID: 20865586
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?
0

LVL 34

Expert Comment

ID: 20866038
Yes
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
###### Suggested Courses
Course of the Month6 days, 10 hours left to enroll