Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
nqlik123
Contributor II
Contributor II

Repeat data for next dates

Hi All, I have data as below..

Date ID Amount
31-Oct-22 A1234 100
30-Nov-22 A4568 400

 

I want my data previous month end data to be repeated for next dates.. till next date. Next date data ie my November data should repeat till date ie today..
 Expected output

 

Date ID Amount
31-Oct-22 A1234 100
01-Nov-22 A1234 100
02-Nov-22 A1234 100
03-Nov-22 A1234 100
04-Nov-22 A1234 100
05-Nov-22 A1234 100
06-Nov-22 A1234 100
07-Nov-22 A1234 100
08-Nov-22 A1234 100
09-Nov-22 A1234 100
10-Nov-22 A1234 100
11-Nov-22 A1234 100
12-Nov-22 A1234 100
13-Nov-22 A1234 100
14-Nov-22 A1234 100
15-Nov-22 A1234 100
16-Nov-22 A1234 100
17-Nov-22 A1234 100
18-Nov-22 A1234 100
19-Nov-22 A1234 100
20-Nov-22 A1234 100
21-Nov-22 A1234 100
22-Nov-22 A1234 100
23-Nov-22 A1234 100
24-Nov-22 A1234 100
25-Nov-22 A1234 100
26-Nov-22 A1234 100
27-Nov-22 A1234 100
28-Nov-22 A1234 100
29-Nov-22 A1234 100
30-Nov-22 A4568 400
01-Dec-22 A4568 400
02-Dec-22 A4568 400
03-Dec-22 A4568 400
04-Dec-22 A4568 400
05-Dec-22 A4568 400
06-Dec-22 A4568 400
07-Dec-22 A4568 400
Labels (4)
1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

An alternative way 

temp:
load date(date#(Date,'DD-MMM-YY')) as DATE,ID,Amount inline [
Date,ID,Amount
31-Oct-22,A1234,100
30-Nov-22,A4568,400
];
NoConcatenate

Main:
Load 
  Date(DATE + IterNo()-1) as DATE
  ,ID
  ,Amount
  ,DateTo
WHILE floor(DATE + IterNo()-1) <= floor(DateTo)
;
load *
  ,coalesce(Previous(DATE),DATE) as DateTo
Resident temp 
Order by DATE Desc;
Drop table temp;

exit Script;

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

6 Replies
RudyKostka
Partner - Contributor II
Partner - Contributor II

SET MonthNames='Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec';

TMP_Input:
LOAD Floor(Date#(Date, 'DD-MMM-YY')) as %Date, * INLINE [
Date, ID, Amount
31-Oct-22, A1234, 100
30-Nov-22, A4568, 400
];

TMP_Table:
LOAD
Tmp_MinDate + IterNo() as %Date
While Tmp_MinDate + IterNo() <= Tmp_MaxDate;
LOAD
Min (FieldValue ('%Date', RecNo ())) - 1 as Tmp_MinDate,
// Max (FieldValue ('%Date', RecNo ())) as Tmp_MaxDate
Floor(Today()) as Tmp_MaxDate
AutoGenerate FieldValueCount ('%Date');

LEFT JOIN (TMP_Table) LOAD * Resident TMP_Input;
DROP Table TMP_Input;

FINAL_Table:
Noconcatenate LOAD
%Date,
Date(%Date) as Date,
IF(IsNull(ID), Peek(ID),ID) as ID,
IF(IsNull(Amount), Peek(Amount),Amount) as Amount
Resident TMP_Table
Order by %Date;

DROP Table TMP_Table;
vinieme12
Champion III
Champion III

An alternative way 

temp:
load date(date#(Date,'DD-MMM-YY')) as DATE,ID,Amount inline [
Date,ID,Amount
31-Oct-22,A1234,100
30-Nov-22,A4568,400
];
NoConcatenate

Main:
Load 
  Date(DATE + IterNo()-1) as DATE
  ,ID
  ,Amount
  ,DateTo
WHILE floor(DATE + IterNo()-1) <= floor(DateTo)
;
load *
  ,coalesce(Previous(DATE),DATE) as DateTo
Resident temp 
Order by DATE Desc;
Drop table temp;

exit Script;

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
nqlik123
Contributor II
Contributor II
Author

Sorry for the late reply, i tried the solution works fine for single id in single date, when i have multiple ids, i'm not able to get the right output

nqlik123
Contributor II
Contributor II
Author

sorry for the late reply, My Id in November "A4568" is also appearing in October, can you help me with this i need the ids to flow to next dates but not to the previous dates

vinieme12
Champion III
Champion III

just make the below highlighted change instead of   <=  , change to  <

WHILE floor(DATE + IterNo()-1) < floor(DateTo)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
RudyKostka
Partner - Contributor II
Partner - Contributor II

The solution corresponded to the task. If multiple IDs are present, it is necessary to complete the assignment. Individual IDs have validity FROM - TO or is it sufficient to CONCATE values from the ID field ?
E.g. :
31-Oct-22 A1234,A1235,A1236 100
30-Nov-22 A4568,A4569,A4570 400
or
31-Oct-22 A1234 100
31-Oct-22 A1235 200
31-Oct-22 A1236 300
30-Nov-22 A4568 400
30-Nov-22 A4569 500
30-Nov-22 A4570 400
or
ID, FROM, TO, VALUE
A1234, 31-Oct-22, 29-Oct-22, 100
A1235, 31-Oct-22, 29-Oct-22, 200
A1236, 31-Oct-22, 29-Oct-22, 300
etc.