Subject Re: [IBO] Running total column
Author Andreas Hesse
Eyal wrote:
>
> Hi,
>
> I use the TIBO* components with 3rd party DB aware controls. I need to
> display accounting data in a grid, which is more or less trivial except...
>
> I need to display a column of the running total - that is, for each
> row the running total = (running total of previous row) + current row.
> For example:
>
> # Date Desc. Amount RunTot
> 1 1/1 Blah 100 100
> 2 2/2 Ding 200 300
> 3 3/3 Dong 300 600
> 4 4/4 Oops -400 200
> Etc.
>
> The problem is that I can't use a calculated column, because for each
> row the calculation event will need to access data from all previous
> rows. This results in the current row changing during the event (which
> wreaks havoc on connected controls), and very slow when there are
> several hundred rows.
>
> Another possible solution is to include a dummy column in the query,
> which creates another column, and then calculate the running totals
> once and store them in that column. However this marks all the rows
> for update, altough nothing really has changed in the underlying DB data.
>
> What I need is a "virtual column" that I can populate with the values
> I want, without disturbing the update status of the rows.
>
> Is there any such thing?
>
> Thanks,
>
> Eyal.
>

I work only with the native IBO Components.
Here is my idea:

define CalculatedFields (RunTot, isCalculated)

in the OnCalculate Event calc your RunTot with RunTot(n) = Amount(n) + RunTot(n-1)
of course RunTot(0) = Amount(0)

RunTot(n-1) means: use the BufferedRows, go one back, and get the value of RunTot

It is O(n), so it should be quick enough with many rows.

But I do not know how to implement it with the TIBO* components.

Andreas