Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increment Counter

Status
Not open for further replies.
Mar 19, 2003
57
0
0
US
Crystal 9 and Oracle 9i

I need help with a formula that increments a counter whenever the value on a field from the previous record is not the same value, otherwise the counter retains the value from the most recent increment. For Example, lets say the table looks like this.....

ID Type

100 ABC
100 BBB
100 CCC
101 VVV
101 TTT
102 FFF

The formula should display the following for each record:

0
0
0
1
1
2

Hope this made sense.
 
Try:

whileprintingrecords;
numbervar ID:= 0;
if
not(onfirstrecord)
and
previous({table.id})<> {table.id} then
ID:=ID+1;
ID

-k
 
I appears you are counting the unique ID's. If so, just use a running total (#RTID) on table.id with Distinct Count as your summary.

Place #RTID in the detail section.

You did not give any further detail so I don't know what you intend to do the number.
 
Except that the first number is supposed to start with zero, Witchita.

I considered having them create a Running total and then in a formula subtract one from it, but...

-k
 
Hmmm... forgot the zero

Then would the following formula work?

//@counter
#RTID - 1

-L
 
Exactly, that's what I meant about another formula subtracting 1 from the RT.

So I decided that I could code one formula in about the same time as I could create a Running total and then create a formula to subtract 1 from it, and it should prove a bit faster, and there's 1 less object.

-k
 
wichitakid,

the running total works fine in the Detail Section. But what if I need to create a GROUP Section to get the same results from the running total?
 
Then insert the running total at the group level. However, you will need to edit the running total and click on reset at the group level.

 
How could the running total work if it's supposed to start with 0, are you using it in a formula?

If you want to use a Running Ttoal to count some Group level, make sure that you're using a distinct count of the group value, and again, it won't display 0 as the first value.

-k
 
Thanks guys. Distinct count works fine.

Synapsevampire, 0 was not mandatory as the starting number. Just used it as an example.

Thanks Again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top