Print Page | Close Window

CR Processing Engine

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=18094
Printed Date: 08 May 2024 at 5:45am


Topic: CR Processing Engine
Posted By: freebird40CR
Subject: CR Processing Engine
Date Posted: 28 Nov 2012 at 6:45am
I am trying to display the RecaptureDonorYearDiff on the detail section of the report. It will display the GiftYear and PreviousGiftYear with no problem but when making the calculation the result for the RecaptureDonorDiff is equal to zero. For example, if GiftYear is 2010 and PreviousGiftYear is 2007, the difference should be 3. Listed below is the formula. The formula is placed in the detail section of the report.

Local NumberVar PreviousGiftYear := Year(Previous({CnGf_1.CnGf_1_Date}));
Local NumberVar GiftYear := Year({CnGf_1.CnGf_1_Date});

Local NumberVar RecaptureDonorYearDiff;

Local BooleanVar RecaptureDonor;

WhilePrintingRecords;

RecaptureDonorYearDiff = GiftYear - PreviousGiftYear;

If RecaptureDonorYearDiff >= 2 Then

    RecaptureDonor = True
Else
    RecaptureDonor = False
;

"RecaptureDonor:                  " + ToText(RecaptureDonor);
"Previous Gift Year:              " + ToText(PreviousGiftYear);
"Gift Year:                      " + ToText(GiftYear);
"Recapture Donor Year Difference: " + ToText(GiftYear) + " - " + ToText(PreviousGiftYear) + " = " + ToText(RecaptureDonorYearDiff);



Replies:
Posted By: hilfy
Date Posted: 29 Nov 2012 at 4:10am
"Previous" works for all records and you're not checking to see whether you're at the start of a group or the end of a group.  This will only work if you're at the end of a group.  Rather than trying to do all of this in a single formula, I would set up separate formulas, something like this (assuming your data is ordered by donation date and that you're grouping on donor):
 
{@PiorYear}
//If the donor has more than one donation date
If Previous({donor group field}) = {donor group field} then
  Year(Previous({CnGf_1.CnGf_1_Date}))
else //default to current year if there is no previous record
  Year({CnGf_1.CnGf_1_Date})
 
{@CurrentYear}
Year({CnGf_1.CnGf_1_Date})
 
{@RecaptureDonorYearDif}
{@CurrentYear} - {@PriorYear}
 
{@RecaptureDonor}
//this evaluates to True or False without the If
{@RecaptureDonorYearDif} >= 2
 
You can then test these formulas to see what the values are.  Then, instead of creating a formula to display the values with the headings, you have a couple of options:
 
1.  Create a separate text object on the report for each label then drag each of the formulas next to its corresponding label.  Format the numbers so that they don't show decimals (your "ToText" calls above, don't do that...)  This makes it very easy to line up the numbers vertically.
 
2.  Create a single text object on the report that contains all of the labels.  Drag the formulas into the text object so that they're embedded in it next to the appropriate label.  Select each formula, right-click, format the number to not have any decimals.
 
-Dell
 


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: freebird40CR
Date Posted: 30 Nov 2012 at 4:24am
mailto:%7b@RecaptureDonorYearDif - {@RecaptureDonorYearDif } formula is returning a Boolean value even though I declared RecaptureDonorYearDiff variable as a NumberVar.
 
 

Local NumberVar PreviousGiftYear := Year(Previous({CnGf_1.CnGf_1_Date}));
Local NumberVar GiftYear := Year({CnGf_1.CnGf_1_Date});
Local NumberVar RecaptureDonorYearDiff;

WhilePrintingRecords;

RecaptureDonorYearDiff = GiftYear - PreviousGiftYear;



Posted By: hilfy
Date Posted: 30 Nov 2012 at 5:02am
Change it to:
 
ptureDonorYearDiff := GiftYear - PreviousGiftYear;


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: freebird40CR
Date Posted: 05 Dec 2012 at 3:09am
Thank you so much, it works! Why didn't it worked without the ":"?


Posted By: hilfy
Date Posted: 05 Dec 2012 at 3:30am
Originally posted by freebird40CR

Thank you so much, it works! Why didn't it worked without the ":"?
 
"=" is a boolean comparison.  ":=" is assignment.  Some programming languages work this way and this is the way that you work with variables in Crystal.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: freebird40CR
Date Posted: 05 Dec 2012 at 4:19am
{@RecaptureDonor}
//this evaluates to True or False without the If
{@RecaptureDonorYearDif} >= 2
 
It did not work. All of the RecaptureDonor results are False.


Posted By: freebird40CR
Date Posted: 05 Dec 2012 at 5:45am

Thank you for the information.



Posted By: freebird40CR
Date Posted: 05 Dec 2012 at 6:03am
{@PiorYear}
//If the donor has more than one donation date
If Previous({donor group field}) = {donor group field} then
  Year(Previous({CnGf_1.CnGf_1_Date}))
else //default to current year if there is no previous record
  Year({CnGf_1.CnGf_1_Date})
 
Thank you, this worked like a charm.


Posted By: freebird40CR
Date Posted: 14 Dec 2012 at 5:44am
It did not work for the FIRST record within the group.


Posted By: hilfy
Date Posted: 17 Dec 2012 at 3:54am
Try this:
 
{@PiorYear}
//If the donor has more than one donation date
If not PreviousIsNull({donor group field}) and Previous({donor group field}) = {donor group field} then
Year(Previous({CnGf_1.CnGf_1_Date}))
else //default to current year if there is no previous record
Year({CnGf_1.CnGf_1_Date})
 
It's not working for the first record because the previous record is null.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: freebird40CR
Date Posted: 19 Dec 2012 at 5:27am

Local NumberVar PreviousGiftYear := Year(Previous({CnGf_1.CnGf_1_Date}));
Local NumberVar GiftYear := Year({CnGf_1.CnGf_1_Date});
Local NumberVar YearDiff;

WhilePrintingRecords;

//If the donor has more than one donation date
If not PreviousIsNull({CnBio.CnBio_SortKey}) and Previous({CnBio.CnBio_SortKey}) = {CnBio.CnBio_SortKey} then
    PreviousGiftYear
else //default to current year if there is no previous record
    GiftYear;

YearDiff := GiftYear - PreviousGiftYear;

Unfortunately, it is picking up the last record in the previous group.


Posted By: hilfy
Date Posted: 20 Dec 2012 at 8:08am
Try this change:
Local NumberVar PreviousGiftYear := Year(Previous({CnGf_1.CnGf_1_Date}));
Local NumberVar GiftYear := Year({CnGf_1.CnGf_1_Date});
Local NumberVar YearDiff;

WhilePrintingRecords;

//If the donor has more than one donation date
If not PreviousIsNull({CnBio.CnBio_SortKey}) or Previous({CnBio.CnBio_SortKey}) = {CnBio.CnBio_SortKey} then
    PreviousGiftYear
else //default to current year if there is no previous record
    GiftYear;

YearDiff := GiftYear - PreviousGiftYear;

-Dell
 


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window