Solved

c# datatable calculated column

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now