Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Percentage formula Post Reply Post New Topic
Page  of 2 Next >>
Author Message
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Topic: Percentage formula
    Posted: 24 Aug 2010 at 12:14am
Can a sum be calculated using a COUNT field as i cant seem to get it right, maybe i'm way off the ball on this though.. formula i'm trying is this....

sum({@weeks } / {Count of HSW.FormDate }) * 100


Can anyone point me in the right direction and bear in mind i'm very new to crystal reporting.

Cheers
Ian   Confused
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Aug 2010 at 3:48am
sum({@weeks })%Count({HSW.FormDate })
or your version would be
 
(sum({@weeks }) / Count({HSW.FormDate })) * 100


Edited by DBlank - 24 Aug 2010 at 3:49am
IP IP Logged
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Posted: 24 Aug 2010 at 9:32pm
Cheers DBlank

How will it look if i need it reversed, the COUNT first then @weeks?

(COUNT({HSW.FormDate})/{@weeks}) *100   ?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 25 Aug 2010 at 3:45am
(COUNT({HSW.FormDate})/SUM({@weeks})) *100  
or
 
COUNT({HSW.FormDate})%SUM({@weeks})
 
you also may want ot deal with the possibility of zero denominator which will give you an error 'cannot deivide by zero'
 
if SUM({@weeks})=0 then 0 else COUNT({HSW.FormDate})%SUM({@weeks})
IP IP Logged
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Posted: 25 Aug 2010 at 9:06am
Thanks DBlank

I must be doing something wrong i appear to get the same result for every record even though i know they should be different..

The formula does use the result of the COUNT and said formula @weeks and divide to show a percentage?

the result of @weeks is 10 and COUNT of HSW.FormDate is 8 and should show 80% but i get the result 141 for every record....any ideas where i may be going wrong?

Cheers

Ian Confused
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 25 Aug 2010 at 9:13am

both of your formulas are looking at the totals for all records (not grouped levels).

if you want to look at grouped data you need to use sumamries that are at the group level. these are constructed generally as:
COUNT(field,groupfield)
SUM(field,groupfield)
Does that address it?


Edited by DBlank - 25 Aug 2010 at 9:14am
IP IP Logged
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Posted: 25 Aug 2010 at 10:04pm
Yes it makes sense but still a little lost how to do that!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Aug 2010 at 3:33am

What is your group structure including field names and for which groups are you trying to get the percentages?

IP IP Logged
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Posted: 26 Aug 2010 at 10:16pm
This counts the total of reports for a contract ControlofFormDate2: Count of HSW.FormDate divided by a result of formula @weeks which is datediff ("w", {CON.OnSiteStart},currentdate) these are placed in my group footer #3.


IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 30 Aug 2010 at 3:53am
What is the field that is being grouped on to create group level 3?
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.