Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
In the first table below is what is currently available for 1 particular customer in our customer database.
In the second table is what i would like to create.
All the in between dates need to be filled based on the calendar, and it needs to pick up the first status till the status changes.
Has someone an idea how to do this? 🙂
Available data:
Customer ID | Status | Date |
1 | No | 20-Mar-19 |
1 | Yes | 17-Mar-19 |
1 | No | 14-Mar-19 |
1 | Yes | 13-Mar-19 |
1 | No | 10-Mar-19 |
Desired output:
Customer ID | Status | Date |
1 | No | 20-Mar-19 |
1 | Yes | 19-Mar-19 |
1 | Yes | 18-Mar-19 |
1 | Yes | 17-Mar-19 |
1 | No | 16-Mar-19 |
1 | No | 15-Mar-19 |
1 | No | 14-Mar-19 |
1 | Yes | 13-Mar-19 |
1 | No | 12-Mar-19 |
1 | No | 11-Mar-19 |
1 | No | 10-Mar-19 |
HI
this script
will do the trick foryou
[Table]:
Load *,
date(date#([Date],'DD-MMM-YY')) as startDate ;
LOAD * INLINE
[
Customer ID,Status,Date
1,No,20-Mar-19
1,Yes,17-Mar-19
1,No,14-Mar-19
1,Yes,13-Mar-19
1,No,10-Mar-19
](delimiter is ',');
/// adding the end date for each date
Table2:
load * ,
date( startDate + iterno()-1) as DateList
while date( startDate + iterno()-1) < endDate;
load *,
if(IsNull(Previous(startDate)),startDate+1,previous(startDate)) as endDate
resident Table
order by [Customer ID], startDate DESC;
drop Table Table;
HI
this script
will do the trick foryou
[Table]:
Load *,
date(date#([Date],'DD-MMM-YY')) as startDate ;
LOAD * INLINE
[
Customer ID,Status,Date
1,No,20-Mar-19
1,Yes,17-Mar-19
1,No,14-Mar-19
1,Yes,13-Mar-19
1,No,10-Mar-19
](delimiter is ',');
/// adding the end date for each date
Table2:
load * ,
date( startDate + iterno()-1) as DateList
while date( startDate + iterno()-1) < endDate;
load *,
if(IsNull(Previous(startDate)),startDate+1,previous(startDate)) as endDate
resident Table
order by [Customer ID], startDate DESC;
drop Table Table;