Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Division by Zero Error Post Reply Post New Topic
Author Message
jabucket
Newbie
Newbie


Joined: 15 Nov 2011
Location: United States
Online Status: Offline
Posts: 7
Quote jabucket Replybullet Topic: Division by Zero Error
     Posted: 15 Nov 2011 at 7:12pm
I am trying to calculate a profit margin by using the formula as follows:

({@Pmt} - {@ExtendedCost}) / {@Pmt}

This was giving me a division by zero error, so I tried implementing this change:

If {@Pmt} <> 0 then
({@Pmt} - {@ExtendedCost}) / {@Pmt}

The error is gone, but it gives the result of 0 for all calculations when the formula results from both @Pmt and @ExtendedCost are both non-zero values.

I'm stuck and would appreciate any help you all can offer.
IP IP Logged
CircleD
Senior Member
Senior Member
Avatar

Joined: 11 Mar 2011
Location: United States
Online Status: Offline
Posts: 251
Quote CircleD Replybullet Posted: 15 Nov 2011 at 9:08pm
Have you tried just >0.Sometimes it's something simple.
IP IP Logged
jabucket
Newbie
Newbie


Joined: 15 Nov 2011
Location: United States
Online Status: Offline
Posts: 7
Quote jabucket Replybullet Posted: 15 Nov 2011 at 9:21pm
I hadn't, but have now to no avail. Have tried:

If {@Pmt} = 0 then 0
else
{@Pmt} / {@ExtendedCost}

If {@Pmt} > 0 then 0
else
{@Pmt} / {@ExtendedCost}

If {@Pmt} < 0 then 0
else
{@Pmt} / {@ExtendedCost}

All of which will return the division by zero error depending on which page of results in the report I am on.
IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 16 Nov 2011 at 2:38am
Now it is  {@ExtendedCost}   you have to test for 0 not {@Pmt}
 
It is always the denominator that will give the divide by zero error.
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 16 Nov 2011 at 5:34am
you could try to
in select expert put
{@Pmt} <> 0
or
If {@Pmt} = 0 then
({@Pmt} - {@ExtendedCost}) * {@Pmt} else
({@Pmt} - {@ExtendedCost}) / {@Pmt}

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 16 Nov 2011 at 7:49am

IMO I would deconstruct the process to see where it breaks down .

Your final formula might be calculating "correctly" but the formuals inside it are not.
If this is a row level calucaltion plce both the {@Pmt} and {@ExtendedCost}  field into the row and then do the math yourself to see you also get the zero results.
If this is group or report level data place theose fields in that location and do the same thing.
This should help you spot where the 'error' is.


Edited by DBlank - 16 Nov 2011 at 7:49am
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum