2nd Most Recent Date
Printed From: Crystal Reports Book — Forum Name: Technical Questions
Posted By: thummel1 — 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
Posted By: DBlank — 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
Posted By: thummel1 — 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
Posted By: DBlank — 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
|