Hey all,
I've got some account level data I'm pulling in from Redshift, and I'm having trouble getting exactly what I need. There's some "interesting" record keeping in this database, so that makes it a bit more complicated.
Basically I've got fields for mortality count and lapse count, which denote if the policy died or lapsed respectively. A 1 means death or lapse, 0 means inforce, and -1 means a previous death or lapse record was reversed. I've got another field called type_of_record, and the only values we care about here are L, R, D, and null. L means lapse, R means reinstated, D means death, and null means inforce.
Lapses: It's possible for a policy to lapse and then be reinstated, so if there's an L on 5/20/2013 and an R on 5/25/2013, then I don't want either of those records. However, if there's an L and no R, then I want the valdate of the most recent lapse.
Deaths: Similar to lapses, if there's a death and no reversal of that death, then I want the valdate of the last recorded death. The part that is confusing me is how to grab only the death record if there was a previous lapse. Right now my workflow is grabbing the most recent lapse and the last recorded death, but if they died, I only want the death record.
Inforce: If there are no recorded lapses or deaths (or they were reversed out of), then I want the most recent valdate where the type_of_record field is null (or empty).
Any help on this would be greatly appreciated!
Edit: Added a record ID to the original dataset and the desired output.
Solved! Go to Solution.
@jrdnjhnsn2 I think I have an idea of where to start with this, but for the data provided could you also provide the expected result data set? There are a variety of ways that you can pick the latest record based on criteria, but I'm not 100% clear on your desired output and format.
@BrandonB I added my desired output for the dataset I provided. I tacked on a record ID for easier comparison. Note that even though the first policy has lots of entries for death and lapse, the sum of everything in their Mortality_Count and Lapse_Count is 0 so I just want to grab record 282 for them. Don't ask how they can die so many times haha I'd like to know too!
@BrandonB Works perfectly! Thanks for your help!!