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
Solved

c# datatable calculated column

Posted on 2014-10-22
3
331 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
  • 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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