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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count every other

Status
Not open for further replies.

kimmylexy

Programmer
Jun 16, 2004
1
US
I am creating a report that counts the allocated fleet per position per district.

For every position the first 6 will get a vehicle. Starting at the 7th position every other one will get a vehicle. So it would be like this....

1 - 6 employees get their own vehicle
7 - would get their own only if there wasn't a 8th employee
once there are 7 and 8 would share vehicles. 9 would have his own until 10 came. then it would be 9 and 10 sharing a vehicle.

How do a create such a formula?
 
I'm assuming District is Group #1 and Positioin is group #2. Create two formulas:

//{@reset} to be placed in the Position group header#2:
whileprintingrecords;
numbervar cnt;
if not inrepeatedgroupheader then
cnt := 0;

//{@cnt} to be placed in the detail section:
whileprintingrecords;
numbervar cnt;
if {#cntwingrp} in 1 to 6 then
cnt := cnt + 1 else
if {#cntwingrp}/2 <> int({#cntwingrp}/2) then
cnt := cnt + 1;
cnt

...where {#cntwingrp} is a running total that counts a recurring field (non-null), evaluates for each record, and resets on change of group: Position.

{@cnt} will count the first six records within the group and then every other one. If you want a display formula in the group footer #2, use this formula:

whileprintingrecords;
numbervar cnt;

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top