Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a Maximum date for a group using variables

Status
Not open for further replies.

banditx42

Technical User
Oct 10, 2002
6
US
On a report I am working on I need to find the maximum date for a field within each group and then perform calculations using that date. Since I have to do a final average on those calculations I cannot use the built in summary to find the maximum date in the field. I have tried using the 3 formula approach, but it does not seem to be working. Here are my three formulas:

@ResetMaxDate (in group header)
DateTimeVar MaxDate;
MaxDate := DateTimeValue (1990, 01, 01)


@FindMaxDate (in details)
DateTimeVar MaxDate;
if {CHS_AUDIT_RESERVES.TRANS_DATE}>MaxDate then MaxDate := {CHS_AUDIT_RESERVES.TRANS_DATE}

@ShowMaxDate (in group footer)
DateTimeVar MaxDate

All of the results come up null! If I test it and make @FindMaxDate just assign MaxDate to the field Trans_Date, MaxDate will display as the Trans_date next to each record in the details, but then the footer will show the value of MaxDate that it was originally assigned to in the header! I have no idea why this is happening. Please help. Thanks.
 
Try:

@ShowMaxDate
WhilePrintingRecords;
DateTimeVar MaxDate;
MaxDate := Maximum({CHS_AUDIT_RESERVES.TRANS_DATE},{GroupField})

Lose @FindMax, and start your formulae off with WhilePrintingRecords if you want to make sure that you don't experience the phenomena of variables reverting back to values assigned in headers when details assign something else...

All the best,

Naith
 
The problem with that method is that it includes a summary function and therefore you cannot perform further summary functions on the formula. What I need to do is subtract the max date from another date field for each group and then average the results from each group.
 
In that case, stick
Code:
Else MaxDate
at the end of @FindMax. You should still start off all 3 of your formulas with WhilePrintingRecords;

Naith
 
1) these formulas should all start with "WhilePrintingRecords".

2) Your reset formula is assinging a Date value to a DateTime variable. You may need to include the time.

3) In some cases I have had to write the assignment this way:

DateTimeVar MaxDate;
if {CHS_AUDIT_RESERVES.TRANS_DATE} > MaxDate
then MaxDate := {CHS_AUDIT_RESERVES.TRANS_DATE}
else MaxDate := MaxDate Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Thanks, it finally worked. Why do these damn things have to be so picky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top