Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Filtering for Max Date Post Reply Post New Topic
Author Message
Legacysh
Newbie
Newbie


Joined: 04 Jan 2008
Location: United States
Online Status: Offline
Posts: 2
Quote Legacysh Replybullet Topic: Filtering for Max Date
     Posted: 04 Jan 2008 at 11:27am
Hi,
 
Am new to this group. I am looking for information on filtering to get only the Max date record to appear when the table has multiple records.
 
Here are the fields:
Emp#, Name, Code, Date completed, Exipration Date
 
Each employee can have multiple codes (certifications), and each code can be entered with multiple dates (as they renew).
 
I just want the Max date to show for each Code
 
I am not doing anything fancy, but creting an export dump of all the employee's most current certification data.
 
I have tried so many things and get errors or no data... so i would love some input.
 
Thanks.
 
Legacysh
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 06 Jan 2008 at 8:51pm
I'm not sure where your problem is since I don't have the details of what you've tried, but one idea I saw Hilfy post a while back is to store on the date field (descending) and then put the date field in the group header. Then suppress the Details section. This will show the max date in the group header and not show any other records.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Lugh
Senior Member
Senior Member
Avatar

Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Quote Lugh Replybullet Posted: 07 Jan 2008 at 4:48am
This is a classic problem in SQL, that is generally solved with a self-join.

SELECT Main.*
FROM MyTable Main
JOIN (SELECT Emp#, Code, Max([Expiration Date]) AS MaxDate
          FROM MyTable
          GROUP BY Emp#, Code) Filter
ON Main.Emp# = Filter.Emp#
AND Main.Code = Filter.Code
AND Main.[Expiration Date] = Filter.MaxDate


There is also another trick you can use in Crystal, if you don't mind bringing in all the data and just suppressing what you don't need.  Create groups, in this case, on Emp# and Code.  Put a suppression criteria on the details section that looks like:

{MyReport.[Expiration Date]} <> Maximum ({MyReport.[Expiration Date]},{MyReport.Code})


IP IP Logged
Legacysh
Newbie
Newbie


Joined: 04 Jan 2008
Location: United States
Online Status: Offline
Posts: 2
Quote Legacysh Replybullet Posted: 07 Jan 2008 at 8:09am
I just want to say thanks. Your second suggestion worked great, and I will use it while i try to work through the first suggestion since it will make the report more efficient.
 
I appreciate the Assistance.
Legacysh
IP IP Logged
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