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

Problem with Conditional Summary Calculations

Status
Not open for further replies.

Nassy

Programmer
Mar 27, 2003
121
GB
Hi

I am creating a report to show monthly Labour Turnover.

In my report I have two totals:


Headcount
Leavecount


In order to calculate the Headcount total and Leavecount total I have two formulas as follows



@Headcount

If Z = 1 then 0 else 1

@Leavecount

If Z=2 then 0 else 1


Where Z is just a field in my table which signifies whether a row relates to Leaver or Headcount

I then get Crystal to total the two formulas to give me a
LeaveCount and Headcount. I then put these totals in the Month group header so that the totals relate to each month

This works fine BUT

If I want to divide the Monthly Headcount figure with the Monthly Leavecount figure I run into trouble as Crystal won't allow me to create make one of my subtotals a percentage of the other subtotal.

I have tried to force the issue by creating a formula with the following code:


whileprintingrecords;
//variable to store Headcount
Numbervar HCount = 0;
//variable to store Leavecount
Numbervar LCount= 0;
//variable to store LabourTurnover
Numbervar LabourTurnvover=0;
select {Z}
case 1: HCount :=HCount+1
case 2: LCount :=LCount+1;

if HCount <> 0 then

LabourTurnover := LCount/HCount * 100
if HCount <> 0 then


But it doesn't work and returns 0.

I am really tearing my hair out over this one
[3eyes]

So any help is much appreciated!

Nassy
 
It looks like you are using the detail values not the subtotal, plus you are making it way to complicated.

Try something like this:

if Sum ( {field2} , {GroupField} ) = 0
then 0 else
Sum ( {field1} , {GroupField} ) /
Sum ( {field2} , {GroupField} )


Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
I am kicking myself now.

Thanks Ken.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top