Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
I'm trying to update a column called PRIORITY_DATE based on specific conditions and seeking guidance or suggestions on how to approach this.
I have a dataset structured as -
PTNO | DOCTOR | APPT_DATE
1 | A1 | 01/21/2021
1 | A1 | 01/30/2021
1 | A1 | 05/02/2021
1 | A1 | 06/04/2021
1 | A2 | 07/04/2021
1 | A1 | 10/04/2021
2 | A2 | 08/04/2021
Required Output:
Date format - MM/DD/YYYY
PTNO | DOCTOR | APPT_DATE | PRIORITY_DATE
1 | A1 | 01/21/2021 | 01/21/2021
1 | A1 | 01/30/2021 | 01/21/2021
1 | A1 | 05/02/2021 | 05/02/2021
1 | A1 | 06/04/2021 | 05/02/2021
1 | A2 | 07/04/2021 | 07/04/2021
1 | A1 | 10/04/2021 | 10/04/2021
2 | A2 | 08/04/2021 | 08/04/2021
I need to update the 'PRIORITY_DATE' column based on the following conditions:
I've tried the following script:
LOAD
*,
if(month(APPT_DATE) - month(firstvalue(APPT_DATE)) <= 3, firstvalue(APPT_DATE), APPT_DATE)
Resident TABLE
group by PTNO, DOCTOR
order by APPT_DATE;
but this would result in
PTNO | DOCTOR | APPT_DATE | PRIORITY_DATE
1 | A1 | 01/21/2021 | 01/21/2021
1 | A1 | 01/30/2021 | 01/21/2021
1 | A1 | 05/02/2021 | 05/02/2021
1 | A1 | 06/04/2021 | 06/04/2021 --> WRONG
1 | A2 | 07/04/2021 | 07/04/2021
1 | A1 | 10/04/2021 | 10/04/2021
2 | A2 | 08/04/2021 | 08/04/2021
Any insights, suggestions, or alternative approaches would be greatly appreciated!
Thank you in advance for the help.
replace previous with peek
if(fabs(month(peek(PRIORITY_DATE))-month(APPT_DATE))<3,Peek(PRIORITY_DATE),APPT_DATE)) as PRIORITY_DATE
try this
tab:
load
PTNO,Doctor,PTNO&'-'&Doctor as key,date(date#(APPT_DATE,'MM/DD/YYYY'),'MM/DD/YYYY') as APPT_DATE
;
load * Inline
[
PTNO,Doctor,APPT_DATE
1 , A1 , 01/21/2021
1 , A1 , 01/30/2021
1 , A1 , 05/02/2021
1 , A1 , 06/04/2021
1 , A2 , 07/04/2021
1 , A1 , 10/04/2021
2 , A2 , 08/04/2021
];
NoConcatenate
tab1:
load *
resident tab
order by key;
drop table tab;
tab2:
load PTNO,Doctor,APPT_DATE,PRIORITY_DATE;
load *,
if(key<>previous(key),APPT_DATE,
if(fabs(month(previous(APPT_DATE))-month(APPT_DATE))<3,Previous(APPT_DATE),APPT_DATE)) as PRIORITY_DATE
Resident tab1;
drop table tab1;
Hi @Ahidhar
The issue here is instead of
if(fabs(month(previous(APPT_DATE))-month(APPT_DATE))<3,Previous(APPT_DATE),APPT_DATE)) as PRIORITY_DATE
I need something like this
if(fabs(month(previous(PRIORITY_DATE))-month(APPT_DATE))<3,Previous(PRIORITY_DATE),APPT_DATE)) as PRIORITY_DATE
however this wont work as PRIORITY_DATE is not defined
replace previous with peek
if(fabs(month(peek(PRIORITY_DATE))-month(APPT_DATE))<3,Peek(PRIORITY_DATE),APPT_DATE)) as PRIORITY_DATE
@Ahidhar
Great it works! Thank you!
To show one record per DoctorsBHF but there could be multiple records with the same DoctorsBHF value.