Board index » delphi » Running total in ClientDataset

Running total in ClientDataset


2005-07-07 04:32:29 AM
delphi267
Hello -
Is it possible to use an AggregateField as a running total in a client
dataset? Or is there perhaps another way to have a running total in a cds?
I'm using Delphi 7 with Woll2Woll's InfoPower and Oracle back end. I want
to set up a running total of one of my fields, but I would like to put it in the
client dataset so that I can change the backend source if need be, which I
anticipate. I have tried several things, but am not getting anywhere.
I was successful at including a running total in the SQL for the source
query, but, as I said, I would rather move that to the client ds.
Any ideas?
Teri O
Columbia, MO
 
 

Re:Running total in ClientDataset

Teri O writes:
Quote
Hello -

Is it possible to use an AggregateField as a running total in a client
dataset? Or is there perhaps another way to have a running total in a cds?
I'm using Delphi 7 with Woll2Woll's InfoPower and Oracle back end. I want
to set up a running total of one of my fields, but I would like to put it in the
client dataset so that I can change the backend source if need be, which I
anticipate. I have tried several things, but am not getting anywhere.

I was successful at including a running total in the SQL for the source
query, but, as I said, I would rather move that to the client ds.

Any ideas?

Teri O
Columbia, MO


When you say running total if field e.g. Income you mean something like
sum(Income)? You tried adding an Aggregate (and sum(Income) in the
Expression property) and this did not succeed?
Could you clarify what do you mean by running total?
 

Re:Running total in ClientDataset

Kostas,
The running total gives the some at that point in the list. For example:
Data Running Total
2 2
2 4
2 6
2 8
--
Bill Todd (TeamB)
 

Re:Running total in ClientDataset

"Bill Todd" <XXXX@XXXXX.COM>writes
Quote
Kostas,

The running total gives the sum to that point in the list. For example:

Data Running Total
2 2
2 4
2 6
2 8

--
Bill Todd (TeamB)
Yes, that is exactly what I mean.
I have used the aggregate (sum(RAINFALL_INCHES), in my case) set up as an
aggregate field. But I having a few problems with that.
One, the aggregate field gives the total of all the numbers instead of the
total to that point ("running" total). I have thought about grouping and
index, but I don't think that will solve my problem.
And, two, I am using Woll2Woll's InfoPower data-aware components, but I can't
get the aggregate field to show up in a TwwDBGrid (though I can see it in a
TDBGrid, so likely an InfoPower problem), nor can I get it to show up in a
list of data fields in a TeeChart TdbChart. I have set the aggregate field
to visible and active, and set the AggregatesActive to on, but no go.
If you have any ideas, please enlighten me. This brick wall isn't budging.
Thanks in advance!
Teri O
Columbia, MO
 

Re:Running total in ClientDataset

Bill Todd writes:
Quote
Kostas,

The running total gives the some at that point in the list. For example:

Data Running Total
2 2
2 4
2 6
2 8

Thanks Bill, now I understand, is there a way to achieve something like
this (as the OP asked) using Cds? I don't have any idea how this could
be done.
 

Re:Running total in ClientDataset

I have never found a way to do it.
--
Bill Todd (TeamB)
 

Re:Running total in ClientDataset

Oh, well. Thanks anyway!
"Bill Todd" <XXXX@XXXXX.COM>writes
Quote
I have never found a way to do it.

--
Bill Todd (TeamB)
 

Re:Running total in ClientDataset

I would do it on the serverside.
Attach a simple Calc field to the dataset and sum it up there.
If you're not doing anything fancy the provider will just iterate
through the dataset an call onCalcFields once for every record.
This will correctly fill the calc field with a running total.
procedure TRDM.qryOnCalcFields(DataSet: TDataSet);
begin
Sum := Sum + Dataset.FieldByName('Value').Value;
Dataset.FieldByName('Sum').Value := Sum;
end;
I'm assuming you have a distinct order in the data (without that a
running total wouldn't make any sense) and editing the data on the
clientside should'nt update the running total.
Ralf
--- posted by geoForum on delphi.newswhat.com
 

Re:Running total in ClientDataset

Ralf Jansen writes:
Quote
I would do it on the serverside.
Attach a simple Calc field to the dataset and sum it up there.
If you're not doing anything fancy the provider will just iterate
through the dataset an call onCalcFields once for every record.

This will correctly fill the calc field with a running total.

procedure TRDM.qryOnCalcFields(DataSet: TDataSet);
begin
Sum := Sum + Dataset.FieldByName('Value').Value;
Dataset.FieldByName('Sum').Value := Sum;
end;

I'm assuming you have a distinct order in the data (without that a
running total wouldn't make any sense) and editing the data on the
clientside should'nt update the running total.

Ralf



--- posted by geoForum on delphi.newswhat.com
That's interesting. However, if a user adds a new value (in the cds),
then this wouldn't be reflected by the running total field until the
data are posted back to the server and then refreshed.
There must be a better way to do this, even my sample database in my
Palm PDA has this capability!
 

Re:Running total in ClientDataset

How big are your datasets?
Since you're using a cds, it could be easier and safer to just re-iterate
the entire dataset and re-compute the running total manually every time a
change is made that affects it...
--
Brent Rose
XXXX@XXXXX.COM