Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: 2nd Most Recent Date Post Reply Post New Topic
Author Message
thummel1
Senior Member
Senior Member
Avatar

Joined: 27 Apr 2012
Location: United States
Online Status: Offline
Posts: 140
Quote thummel1 Replybullet Topic: 2nd Most Recent Date
    Posted: 14 Oct 2016 at 5:48am
Hi, I'm using Crystal 2011. I'm trying to return only the second most recent date and rate from a table for employees. An employee could have 5 dates, I need the second most recent only to appear. My example (before grouping) looks like this:
Employee ID     Date            Rate
1234             1/1/1998       40
1234             5/2/2010       42
1234             11/12/2015    44
1234             3/1/2016       46
1155             1/1/2016       27
1155             2/27/2016      29

I only want the second to most recent date with the rate:
Employee ID     Date            Rate
1234             11/12/2015    44
1155             1/1/2016       27

I've tried the previous formula, which tells me which one is the second to most recent, but I cannot add this to my selection criteria. Your suggestions are welcome.

Edited by thummel1 - 14 Oct 2016 at 5:49am
"Press any key to continue. Where's the 'Any' Key?" ~Homer Simpson
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 Oct 2016 at 8:09am
if you are hoping to actually select on this you could consider something like SQL RANK with a PARTITION to set a create an ordered number which would eventually get you to a value where you could select '2' from the result for each employee

Edited by DBlank - 14 Oct 2016 at 8:09am
IP IP Logged
thummel1
Senior Member
Senior Member
Avatar

Joined: 27 Apr 2012
Location: United States
Online Status: Offline
Posts: 140
Quote thummel1 Replybullet Posted: 14 Oct 2016 at 9:08am
Thank you, I was able to pull in the 2nd to most recent date by grouping on employee ID, the choosing a Summary on the date, choosing "Nth Largest is": and then I selected 2. Now I just need to pull in the rate of pay that ties with this date. Any quick suggestions on that are welcome, else I'll be tinkering for a while I think. Thanks

Edited by thummel1 - 14 Oct 2016 at 9:14am
"Press any key to continue. Where's the 'Any' Key?" ~Homer Simpson
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 Oct 2016 at 9:15am
in SQL (maybe in a command but I have not tried it) you can create a value using something like
RANK() OVER(PARTITION BY EmployeeId ORDER BY EmployeeId , Date DESC) AS RowValue

Edited by DBlank - 14 Oct 2016 at 9:15am
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.063 seconds.