Link to home
Start Free TrialLog in
Avatar of z_darius
z_darius

asked on

Cumulative totals in dbgrid

I have the following problem:
A a grid, fed by a ClientDataset shows hours worked.
There is one entry per record and I need to be able to show total hours as they grow with each record.

for instance

Date   Dept  Hours   Total
==========================
April    A     5         5
May      B     3         8
May      C     3        11
May      C     1        12
June     A     4        16

The data set will be subject to filter by date and other field sand I need to be able to maintain consistency in the amounts of totals.

i.e. if I filter the above to see only May records I'd like to show totals only for what's displayed like in the example below:

Date   Dept  Hours   Total
==========================
May      B     3         3
May      C     3         6
May      C     1         7

I would also like to maintain the increasing sum in the "Total" column regardles of the whic field is indexed during runtime.  So if the records for May were to be sorted in descending order the display wwould show:

Date   Dept  Hours   Total
==========================
May      C     3         3
May      C     1         4
May      B     3         7

I was playing with aggregate fields but somehow I'm missing something. I'd like this functionality to be implemented on the client side rather than through SQL.

Any ideas? Preferably a short example.
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Hi z_darius,

Ok, I will prepare one. Just a moment.

------
Igor.
ASKER CERTIFIED SOLUTION
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
listening
Avatar of z_darius
z_darius

ASKER

ITugay,

The code as presented doesn't compile. Out of the box I am getting access violation error on first instance of SM.Clear. My proggie uses a number of forms and data module and I guess the order of creation screws me up. However, your code gave me a precious idea and therefore I feel you deserve the points.
Thanx.

z_darius
Yes, it seems SM doesn't created. You can make it global variable and create/destroy  it in initialization-finalization sections.

------
Igor.