Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Dynamic division forumula Post Reply Post New Topic
Page  of 2 Next >>
Author Message
rlivermore
Groupie
Groupie


Joined: 27 Sep 2012
Online Status: Offline
Posts: 70
Quote rlivermore Replybullet Topic: Dynamic division forumula
     Posted: 11 Jan 2013 at 8:13am
Running CR 10 Pro
Our fiscal year is from December 1 to November 30, I have a working running total for each sales rep. Would like to setup a running average for each rep's year to date totals.
 
Example of what I'd to accomplish, if possible, report is run from December 1,2012 to today which is 2 months into our fiscal year.
 
Name:   YTD:         Ave:
RepA     500          250
RepB     1,000       500
 
If ran next month with new totals
Name:    YTD:        Ave:
RepA      900          300
RepB      2,000       667
 
 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 Jan 2013 at 10:08am
i'm an not a running total user, but what I would do is create a running total count of the number of items that comprise the running total,
 
then all you need to do is divide your running total by the running count...
 
HTH
IP IP Logged
rlivermore
Groupie
Groupie


Joined: 27 Sep 2012
Online Status: Offline
Posts: 70
Quote rlivermore Replybullet Posted: 11 Jan 2013 at 10:26am
Unless I'm not understanding your suggestion that won't work. Looking for a YTD average for each rep based on the total dollar amont sold by rep and divided by the number of months into the fiscal year at the time the report is run.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 Jan 2013 at 12:14pm
ok,
so if you know the number of months into the fiscal year, just divide your running total per rep by that number.
IP IP Logged
rlivermore
Groupie
Groupie


Joined: 27 Sep 2012
Online Status: Offline
Posts: 70
Quote rlivermore Replybullet Posted: 14 Jan 2013 at 4:30am
True, that does work for manual manipulation but I'm wanting to make this a dynamic option, if possible.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Jan 2013 at 7:27am
I think that I am confused or perhaps I misunderstood.
 
You want a average for each rep that is the (YTD sales / months YTD), at least that is what I thought you said.
 
If this is so, all you need to do is determine how many months have passed in the fiscal year. The only question would be complete months or partial.
 
In January, you are 1 complete month into the fiscal year, or 2 if you include January....
or am I missing your intent?
 
 
IP IP Logged
rlivermore
Groupie
Groupie


Joined: 27 Sep 2012
Online Status: Offline
Posts: 70
Quote rlivermore Replybullet Posted: 14 Jan 2013 at 8:04am
Let me try and clarify...I would like the report to be able to do the division based on the current date instead of my going into the report each month to manually manipulate the division number for accurate calcuations.
 
If the current date is December then the report would divide each rep's totals by 1 if the current date is March it would divide by 4 if the current date is November it would divide by 12, etc...
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Jan 2013 at 8:38am
number to divide by:
shared numbervar mnths;
local numbervar x :=month({?dateParameter});
if x < 12 then
  mnths := x +1;
else
  mnths := 1;
mnths
 
now just use the variable mnths to divide your reps total YTD sales.
 
IP IP Logged
rlivermore
Groupie
Groupie


Joined: 27 Sep 2012
Online Status: Offline
Posts: 70
Quote rlivermore Replybullet Posted: 14 Jan 2013 at 9:34am
Sorry but the code you listed is beyond my understanding, do I simply copy and paste the code you listed in my current "manual" formula? I don't know what you mean by "just use the variable mnths to divide your reps total YTD sales".
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Jan 2013 at 10:59am
since all values would be divided by the same value, I would probably put this in a formula that i would place in the report header...so it is only called once. In addition to hide the number, I would replace the last line with ""...but for the initial debugging, I would leave the code alone (just to make sure that the value is what you think it should be)
 
As to how to use it:
where you want the average to be calculated you would add:
shared numbervar mnths;
... your code
repsTotalSalesYTD / mnths
 
which parts don't you understand?
basically I declare some values I want to use, I use the date parameter that your user has entered to determine what month it is (month({?dateparameter}). If the month is not december (x<12), I add 1 to it, as that is the number of month in the fiscal year that have elapse. If it is December (x=12), then only 1 month has occurred.  I stored this value in variable that is accessible from anywhere in the report.  Later when you want to use the value, you just tell the report what value you want to use (shared numbervar)
 
HTH
 
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