cancel
Showing results for 
Search instead for 
Did you mean: 

Divide by zero

Former Member
0 Kudos

Post Author: skootsu

CA Forum: Formula

Can any one help me with a divide by zero error? I have two fields that should result in either a positive, negative or zero value.

Example, I have fields for:

@RGTime is {OPERATION.SETUP_HRS}+{OPERATION.RUN}

@RPTime is {OPERATION.ACT_SETUP_HRS}+{OPERATION.ACT_RUN_HRS}

All of these fields can contain either a 0 or a positive value. I need to get a Variance. I made my formula for

@Variance is {@RoutedTime}/{@RptdTime} I am getting the divide by zero error. Example date on a record is:

@RGTime=0.00 and @RPTime=0.02, thus @Variance should equal -0.02

How can I code for this?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Post Author: pandabear

CA Forum: Formula

You're right...if he wants the average. Also, variance is not-negative. The squares are positive or zero. I guess the question is,

is the variance really wanted here. Using the function takes care of the "0" and (hopefully...) getting the proper variance, even by

group. So, my friend. You say you want the variance, but your example gets the average...

Which do you really want ?

The Panda (...awaits...)

Former Member
0 Kudos

Post Author: haint2105

CA Forum: Formula

hi Skootsu,I think the very simple way like this:If ({@RptdTime} = 0 then 0Else {@RoutedTime}/@RptdTime}

Former Member
0 Kudos

Post Author: pandabear

CA Forum: Formula

Try this:

The following examples are applicable to both Basic and Crystal syntax:

Variance({file.AMOUNT})

Calculates the variance of all values in the Amount field.

Variance({file.RESULTS}, {file.DATE},"daily")

Calculates the variation for each group of laboratory test results in the Results field. The test results are separated into groups whenever the value in the Date field changes to a new day.

The following examples are applicable to Crystal syntax:

Variance({file.SCORES}, {file.TEACHERS}) % Variance({file.SCORES})

Groups values in the Scores field by teacher, and calculates the variance for each teacher group as a percentage of the variance of the values for the entire report (for all teachers listed).

Variance([{file.QTY1}, {file.QTY2}, {file.QTY3}, {file.QTY4}])

Returns 17.00 where Qty1 = 2, Qty2 = 2, Qty3 = 10, and Qty4 = 8.

Comments

Variance is calculated using the following technique:

It calculates the average (mean) value for the items in the sample.

It subtracts the average value from the value of each item.

It squares the difference for each item.

It adds the squared differences for all of the items in the sample.

It divides the sum by one less than the number of items in the sample (N - 1). The result is the variance. Compare this final step to the PopulationVariance.