In one of the threads of this forum an interesting problem came up. Given a sequence of records, for example
we need to add a column of indicators that would assume 1 every time a new value happens in the Field, otherwise it will be 0. That is
I suggested the following solution.
We add two running totals fornulae: RT1 and RT2. The first one would count the records distinct, the second one would just count the records:
That is
The indicator should assume 1 every time the RT1 changes its value. As the
fumction is not working for running totals, I simulated the function with the following formula:
In the formula the global variable T keeps the previous value of RT1, while P assumes the difference between current and previous values of RT1. The RT2 is needed only to process the first record, for which there is no previous, and indicator is always 1 on the first record.
For some reason this solution which works fine on all my tests is not workig for the guy who posted the original problem.
Why this may happen?
Also: what are other ways of building the Indicator?
All comments appreciated.
Code:
Field
=====
A
A
A
B
A
C
D
B
Code:
Field Indicator
===== =========
A 1
A 0
A 0
B 1
A 0
C 1
D 1
B 0
We add two running totals fornulae: RT1 and RT2. The first one would count the records distinct, the second one would just count the records:
That is
Code:
Field RT1 RT2
===== === ===
A 1 1
A 1 2
A 1 3
B 2 4
A 2 5
C 3 6
D 4 7
B 4 8
Code:
Previous
Code:
//@Indicator
whileprintingrecords;
Global NumberVar T;
NumberVar P;
if {#RT2}>1 then P:={#RT1}-T else P:=1;
T:={#RT1};
P;
Code:
Field RT1 RT2 Indicator
===== === === =========
A 1 1 1
A 1 2 0
A 1 3 0
B 2 4 1
A 2 5 0
C 3 6 1
D 4 7 1
B 4 8 0
For some reason this solution which works fine on all my tests is not workig for the guy who posted the original problem.
Why this may happen?
Also: what are other ways of building the Indicator?
All comments appreciated.