?
Solved

c# datatable calculated column

Posted on 2014-10-22
3
Medium Priority
?
351 Views
Last Modified: 2014-10-23
Should be a simple question really...

I have a datatable in a c# app that has these columns:
GroupID
MemberID
MemberBalance
MemberWeight (need to calculate this) = MemberBalance / SUM(MemberBalance) Group by GroupID

Data looks like this:
data.png
0
Comment
Question by:timberadmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:louisfr
ID: 40397490
Create another table with GroupID and SumMemberBalance columns.
Create two child-parent relations (one in each direction) between the two tables.
Set the second table's MemberBalance Expression property to Sum(Parent.MemberBalance)
You can then set the Expression of the MemberWeight of your table to MemberBalance/Parent.SumMemberBalance
0
 

Author Comment

by:timberadmin
ID: 40397873
Thanks Louis. This works. Is there a way to do this without having to create additional tables?
0
 
LVL 11

Accepted Solution

by:
louisfr earned 2000 total points
ID: 40399226
Not with a computed column, because there is no "group by" available. The other way is to do the work yourself, which means adding code to compute the column value each time you add, change or delete a row (e.g. using the RowChanged and RowDeleting events).

There was an error in my previous comment. You only need one relation, with the auxilliary table as parent, and the Expression would be "Sum(Child.MemberBalance)"
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question