Solved

c# datatable calculated column

Posted on 2014-10-22
3
348 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 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

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 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