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

Variable is incrementing 3

Status
Not open for further replies.

dkeller

IS-IT--Management
Nov 22, 2002
7
US
I have a Variable formula to count the number of customers that are New, returning, or Out of Business. I have a variable formula for each incrementing the count by one based on their sales. These variables is in the group footer for the customer. I created separate variable to print the total counts in the group footer for the division.
The total that prints is incrementing by one based on the value of the last customer. For example if the last customer is Out of Business then the Out of Business counter in overstated by 1.
Here is the Out of Business formula for the counter that is in the group footer for the customer

//@LYOBCountDiv
WhilePrintingRecords;
NumberVar LYOBCountDiv:=iif({@LYOB} <> 0, LYOBCountDiv +1, LYOBCountDiv);

Here is the formula to print it on the Group Footer for Division.

//@LYOBCountDivPrt
WhilePrintingRecords;
NumberVar LYOBCountDiv;

LYOBCountDiv is only on the Group Footer by Customer and LYOBCountDivPrt is only on the Group footer by Division.
This is what I get in the report

Customer1 New Out Of Bus Count = 0
Customer2 Repeat Out Of Bus Count = 0
Customer3 OB Out Of Bus Count = 1

Division Footer
New Count = 1
Repeat Count = 1
Out of Bus Count = 2
In this case New and Repeat are correct and Out of Bus should be 1. If the last customer was a New customer then the New count is wrong.

What am I Missing? I am using Crytal 8.5
Thanks!
 
Try first to use ":=" instead of "=" when you set a value for a variable.

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
I am. Here is the formula to set the variable
//@LYOBCountDiv
WhilePrintingRecords;
NumberVar LYOBCountDiv:=iif({@LYOB} <> 0, LYOBCountDiv +1, LYOBCountDiv);

Is that the one you where referring to?

 
Do you reset the variable in the Divison group header?

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
Yes! Here is the reset formula. The variables are resetting, the only problem is the extra count from the last customer footer record.

WhilePrintingRecords;
NumberVar TYSameCountDiv:= 0;
NumberVar LYSameCountDiv:=0;
NumberVar TYNewCountDiv:= 0;
NumberVar LYOBCountDiv:=0;
NumberVar TYCountDiv:=0;
NumberVar LYCountDiv:=0;
NumberVar LYNoOrderCountDiv:=0;

Thanks!
 
Maybe the problem is in {@LYOB} formula.

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
Try changing this formula (no need to use IIF):

//@LYOBCountDiv
WhilePrintingRecords;
NumberVar LYOBCountDiv;
if {@LYOB} <> 0 then
LYOBCountDiv := LYOBCountDiv + 1 else
LYOBCountDiv := LYOBCountDiv;

If this doesn't correct the problem, please show the content of {@LYOB}. Also make sure you have removed any old formulas that might be in the group footer that could be accumulating this variable.

-LB
 
Testing your formula and it works just fine. So, you need to find the issue somewhere else.

The only explanation I got is that you may have accidentally put the //@LYOBCountDiv formula in the division footer instread of //@LYOBCountDivPrt

 
I found the problem. Thanks for all your help.
I was using the variable field in another calculation in the group footer. The other formula was used to calculate average sales per customer type.

If {@LYOBCountDiv} = 0 then 0 else
{@TYOBSumPrt}/{@LYOBCountDiv}

I changed this to
If {@LYOBCountDivPrt} = 0 then 0 else
{@TYOBSumPrt}/{@LYOBCountDivPrt}

My counts are all correct.

Thank you for all of your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top