Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Percentages & Divison by Zero Issue? Post Reply Post New Topic
Page  of 2 Next >>
Author Message
FECSII
Newbie
Newbie
Avatar

Joined: 21 Sep 2009
Location: United States
Online Status: Offline
Posts: 22
Quote FECSII Replybullet Topic: Percentages & Divison by Zero Issue?
     Posted: 13 Oct 2011 at 3:31am
Hello,
Having trouble figuring out the best way to 1) get the difference between the 2 most current records within a group and 2) calculate the difference displayed as a percentage.
 
The data is Grouped by Item and Sorted by Date Descending
 
For Instance:
 
Item Group A
           15 10/10/2011
           43 10/08/2011
           22 09/28/2011
 
Item Group B
           0  10/12/2011
           21 09/02/2011
           11 08/25/2011
 
I created 2 formula fields:
 
Current ---> {InventoryActPkgCostHist.ActPkgCost}
Previous --> previous({InventoryActPkgCostHist.ActPkgCost})
Then created a 3rd formula field for percentage:
 
Percentage -->
 
If{InventoryActPkgCostHist.ActPkgCost}=0
then 0
else
({@Current})/({@Previous})
 
But I am getting a divison by zero error. How can I get around this?
 
I am definitely not an expert and am not sure if I am in the right path for what I am trying to accomplish, any guidance would be greatly appreciated.
 
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Oct 2011 at 3:50am
you are dividing by the previous value so your if has to addess that
if previous({InventoryActPkgCostHist.ActPkgCost})=0 then 0 else
{InventoryActPkgCostHist.ActPkgCost}%previous({InventoryActPkgCostHist.ActPkgCost})
IP IP Logged
FECSII
Newbie
Newbie
Avatar

Joined: 21 Sep 2009
Location: United States
Online Status: Offline
Posts: 22
Quote FECSII Replybullet Posted: 13 Oct 2011 at 4:29am
that was too simple, thank youEmbarrassed
IP IP Logged
FECSII
Newbie
Newbie
Avatar

Joined: 21 Sep 2009
Location: United States
Online Status: Offline
Posts: 22
Quote FECSII Replybullet Posted: 14 Oct 2011 at 10:03am

Quick Question

How can I reset the formula to calculate within its group? I have this formula but not working correctly:
 
//SourceFormula
WhilePrintingRecords;
BooleanVar Reset;
NumberVar SourceFormula;
If not Reset Then
SourceFormula:= If previous({InventoryActPkgCostHist.ActPkgCost})=0 then 0 else
{InventoryActPkgCostHist.ActPkgCost}%previous({InventoryActPkgCostHist.ActPkgCost})
Else
SourceFormula :=0;
Reset := False;
SourceFormula
 
Help?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Oct 2011 at 3:44am
usually you need to use 3 formulas for resetting and displaying at the group level
first sets it to 0 palced inm a group header
second calculates in details row
third displays in the group footer
IP IP Logged
FECSII
Newbie
Newbie
Avatar

Joined: 21 Sep 2009
Location: United States
Online Status: Offline
Posts: 22
Quote FECSII Replybullet Posted: 17 Oct 2011 at 6:12am

Thanks for the reply...

It makes sense to need a reset in the group header and the calculation in the details row, but what type of formula goes in the group footer?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Oct 2011 at 6:22am
usually just a display.
somtimes you can use the calcualtion formula (detail record) but if it is an incrimantal row change it may add an extra row when moving from the last detail row to the group footer
IP IP Logged
FECSII
Newbie
Newbie
Avatar

Joined: 21 Sep 2009
Location: United States
Online Status: Offline
Posts: 22
Quote FECSII Replybullet Posted: 17 Oct 2011 at 6:26am
Thank you, I will do some research...
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Oct 2011 at 6:33am
examples are in a lot of posts.
I almost always use Running Totals where many prefer variable formulas.
here is an example
 
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: 18 Oct 2011 at 3:26am

Running totals are good, and simple, when the field you want to total is available. But all too often it is a formula or some other later pass field, and that is when you need variable formulae.

And then you get used to thinking that way :-)

IP IP Logged
Page  of 2 Next >>
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