Hi,
I have the following data table with the first 4 columns being the input and last 2 being the output required. I tried to join two tables to combine column 1-3 and column 4 by matching ID = ID and Adm.Date = Ref.Date. Now I want two output columns (Adm. Date_1 and Dis_Date_1) as shown below. I need the Adm.Date and Dis.Date populated for all the Ref.Date between range of Adm.Date and Dis.Date and missing value for those which does not fit into the date range. I was able to get respective Adm. Date and Dis.Date using if and lag function only for next following record and not for all the records in that range. Please let me know if there's any way to find an appropriate solution to this problem.
Thanks in advance.
| ID | Adm. Date | Dis.Date | Ref.Date | Adm.Date_1 | Dis.Date_1 |
| 12 | 2/12/2014 | 15/12/2014 | 2/12/2014 | 2/12/2014 | 15/12/2014 |
| 12 | | | 3/12/2014 | 2/12/2014 | 15/12/2014 |
| 12 | | | 6/12/2014 | 2/12/2014 | 15/12/2014 |
| 13 | | | 10/1/2015 | | |
| 13 | 6/1/2016 | 25/1/2016 | 6/1/2016 | 6/1/2016 | 25/1/2016 |
| 13 | | | 10/1/2016 | 6/1/2016 | 25/1/2016 |
| 13 | | | 11/1/2016 | 6/1/2016 | 25/1/2016 |
| 13 | | | 12/1/2016 | 6/1/2016 | 25/1/2016 |