Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Please help. Division by zero error Post Reply Post New Topic
Author Message
dawnh44
Groupie
Groupie


Joined: 25 Sep 2011
Online Status: Offline
Posts: 79
Quote dawnh44 Replybullet Topic: Please help. Division by zero error
     Posted: 11 Oct 2011 at 9:23am
Hello,
 
I'm getting a division by zero error with the following formula:
 
if {pc_renew;1.EFF_START_DT} < date(dateadd('yyyy', -1, date(year(today), month(today), 01))) then
    ({pc_renew;1.count} % {pc_renew;1.EE_Total})
else
    ({pc_renew;1.count} % ({pc_renew;1.EE_Total}) * (12/datediff('m', {pc_renew;1.EFF_START_DT}, date(year(today), month(today), 01))))
 
Any suggestions...please.
 
Thank you in advance.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Oct 2011 at 9:26am
{pc_renew;1.EE_Total})=0 then 0 else
if {pc_renew;1.EFF_START_DT} < date(dateadd('yyyy', -1, date(year(today), month(today), 01))) then
    ({pc_renew;1.count} % {pc_renew;1.EE_Total})
else
    ({pc_renew;1.count} % ({pc_renew;1.EE_Total}) * (12/datediff('m', {pc_renew;1.EFF_START_DT}, date(year(today), month(today), 01))))


Edited by DBlank - 11 Oct 2011 at 9:27am
IP IP Logged
dawnh44
Groupie
Groupie


Joined: 25 Sep 2011
Online Status: Offline
Posts: 79
Quote dawnh44 Replybullet Posted: 11 Oct 2011 at 9:34am
Hello,
 
I'm still getting the error.  It's highlighting (12/datediff('m', {pc_renew;1.EFF_START_DT}, date(year(today), month(today), 01))).  I can't seem to figure out why.
 
Thank you again.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Oct 2011 at 9:46am
Originally posted by dawnh44

datediff('m', {pc_renew;1.EFF_START_DT}, date(year(today), month(today), 01))
 
oops..did not see that division in the formula ...
a couple of things about this formula...
the second part is overly complex. You do not need the first of the month as it is written. datediff(month) always calculates the difference in the month value regardless of the actual day of the month (e.g datediff('m', date(2011,10,31), date(2011,11,1)) will still return 1 even though it is only 1 day apart).
therefore
datediff('m', {pc_renew;1.EFF_START_DT}, currentdate)
will give you the same result as what your formula and is easier to manage.
 
now specifically your division by zero issue:
the datediff('m', {pc_renew;1.EFF_START_DT}, currentdate) formula will always get a 0 when the EFF_start_date value is any value during the current month.
Therefore you will alwasy get this error on any date row in your record set where the EEF_start_date is in the current month.
I am not sure how to fix it as I am not sure exactly what you desire to accomplish.
Does that help?


Edited by DBlank - 11 Oct 2011 at 10:58am
IP IP Logged
dawnh44
Groupie
Groupie


Joined: 25 Sep 2011
Online Status: Offline
Posts: 79
Quote dawnh44 Replybullet Posted: 12 Oct 2011 at 2:27pm
Again...You are a genious.  Thank you again!!!!
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