Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: How to calculate last 12 months, 6 months, 3 month Post Reply Post New Topic
Author Message
Remi
Newbie
Newbie


Joined: 17 Jun 2014
Online Status: Offline
Posts: 3
Quote Remi Replybullet Topic: How to calculate last 12 months, 6 months, 3 month
    Posted: 18 Jun 2014 at 11:05pm
Hi All Crystal Experts,

In my report, I have monthly view of data and I grouped by report by Months.  I have three prompts- Year, Startdate and Enddate. If I give 2013 as year, 1/1/2013 as start date and 05/01/2013 as end date then report shows monthly view of data for Jan-13, feb-13, Mar13, Apr-13 and May-13. Now I have to include three more columns in reports -12 months view, 6 months view and 3 months view.  so for each month, I want to show last 12month,  6 month and  3 months data. Like for Jan-13 month, in column 6 months view, I want to show data for last 5 months including current month i.e. Jan-13+Dec-12+Nov-12+Oct-12+Sep-12+Aug-12 and in Column 12months view, I want to show accumulated data of last 11 months(including current month) and in 3 months view, data for last 2 months(including current month).

How to calculate these 3 fields? Any help would be much appreciated.

 

Thanks,

Remi

Thanks,
Remi
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 19 Jun 2014 at 4:57am
I would say that the most effective method would be to write a stored procedure to do all of this for you.

If that is not an option, the next viable solution is a subreport for each column...though this might slow your report to a crawl.

Why? In order for you to get the last year of data into the report, the effective dates become a year earlier, and all of that data will probably mess up your report as you would get more month columns (12 more). By using a subreport, you can display pull as much data as needed (but it's in another report, so you don't see it) and display the result.

Thinking about it, you might be able to get away with just 1 subreport for all 3 columns, though I am not positive about that...originally I had thought 3 subreports, 1 for each column.

Hopefully one of these ideas will lead to a solution...or someone else will suggest another path.
IP IP Logged
Remi
Newbie
Newbie


Joined: 17 Jun 2014
Online Status: Offline
Posts: 3
Quote Remi Replybullet Posted: 19 Jun 2014 at 10:36pm
Thanks Lockwelle.
 
I tried your solution and created one subreport for last 12 months view but it seems that it is not showing any data in this column.
 
I have created subreport like this way:
 

(1) "Running total formula" (which I am using and placing on group footer):

Field to summarize- @Cash_total

(ii) Evaluate (use a formula):

WhilePrintingRecords;

NumberVar Cash_total_12 months;

If Month ({@Month_PostDate}) In [(Month {?StartPostDate} - 11) to Month {?StartPostDate}] Then

   Cash_total_12 months :=  Cash_total_12 months + {@Cash_Total};

(iii) Reset (use a formula):

WhilePrintingRecords;

NumberVar Cash_total_12 months=0;

And if I don't use Runningtotal in subreport then what would be 12 months formula?

I am new to this concept of Crystal. Please help.
Thanks,
Remi
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 25 Jun 2014 at 4:57am
I don't think that you need reset...after all, what if your last record is from 2 years ago, then your total would be 0. I am not a running totals guy. It would seem that you have coded everything that you need in the formula, you could just display the result at the end of report.

I think what I would do is:
Put a Record Selection Formula into the report that would be the 12 month logic that you used in the formula. Now that the only records in the subreport are for the prior 12 months you can just do a SUM() on the field you want and report that

HTH
IP IP Logged
Remi
Newbie
Newbie


Joined: 17 Jun 2014
Online Status: Offline
Posts: 3
Quote Remi Replybullet Posted: 07 Jul 2014 at 2:50am
Hi Lockwelle,
 
Instead of creating sub report, I defined Array in my report.
the below are arrays which I defined in my report to calculate 12 months formula.
1. first I initialized array with this formula:
whileprintingrecords;
Shared Numbervar Array CashTotalArray;
Redim Preserve CashTotalArray[1000];
Shared Numbervar CashTotalCounter:=1;
 
2. Then I created second formula to calculate sum
 
whileprintingrecords;
Shared Numbervar Array CashTotalArray;
Redim Preserve CashTotalArray[1000];
Shared Numbervar CashTotalCounter;
CashTotalArray[CashTotalCounter]:=Sum({@Cash_total}, {@Month_PostDate}, "monthly");
CashTotalCounter:=CashTotalCounter+1;
Sum({@Cash_total}, {@Month_PostDate}, "monthly")
 
3. Then I created third formula for 12 months sum
 
EvaluateAfter({@fCashTotalArray-2 Update});
Shared Numbervar Array CashTotalArray;
Shared Numbervar Counter;
Shared Numbervar MonthCounter;
//for counter:=  1 to 12 do
if MonthCounter>=12
 
    then Sum(CashTotalArray[(MonthCounter-11) to MonthCounter])
    else 0
 
 
As I used MonthCounter here so I created two new formula to initialize and update Monthcounter.
 
1. To initiate Monthcounter:  Shared Numbervar MonthCounter:=1;
 
2. To update Monthcounter: 
 
Shared Numbervar MonthCounter;
MonthCounter:=MonthCounter+1;
 
 
so If I put third formula( for 12 months sum) in report, it gives me zero (0) values. could you please have a look into formulas and tell me where am I wrong?
 
Thanks,
Remi
Thanks,
Remi
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 07 Jul 2014 at 6:19am
first question, do you have a filter on the report to only select data for a certain date range? if so, does it go back 12 months? if not, the formulas won't work as there is no data to populate them with.
IP IP Logged
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.016 seconds.