Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Repeat each row in a table until the enddate

Hi ,

Here is the example , i am trying to do in the load script. Is there any easy way to do it in qlikview

Current table

KeyNameStartDateEndDate
XYZ201307201309
BBB201308201309
CCC201312

201402

Per name it has to repeat until the end date and start date has to change according

Desired Table:

KeyNameStartDateEndDate
XYZ201307201309
XYZ201308201309
XYZ201309201309
BBB201308201309
BBB201309201309
CCC201312201402
CCC201401201402
CCC201402201402

Please Advise.

I am thinking of creating rowno() and looping it or iterno().

let me know if there are any easy ways

Thanks

rk

1 Solution

Accepted Solutions
Nicole-Smith

This should do the trick:

Temp:

LOAD KeyName, date#(StartDate, 'YYYYMM') as StartDate, date#(EndDate, 'YYYYMM') as EndDate INLINE [

    KeyName, StartDate, EndDate

    XYZ, 201307, 201309

    BBB, 201308, 201309

    CCC, 201312, 201402

];

Data:

NoConcatenate LOAD

    KeyName,

    date(AddMonths(StartDate,IterNo()-1), 'YYYYMM') as StartDate,

    EndDate

Resident Temp

while EndDate - addmonths(StartDate, IterNo()-1) >= 0;

DROP TABLE Temp;

I've also attached a working example.

View solution in original post

5 Replies
Nicole-Smith

This should do the trick:

Temp:

LOAD KeyName, date#(StartDate, 'YYYYMM') as StartDate, date#(EndDate, 'YYYYMM') as EndDate INLINE [

    KeyName, StartDate, EndDate

    XYZ, 201307, 201309

    BBB, 201308, 201309

    CCC, 201312, 201402

];

Data:

NoConcatenate LOAD

    KeyName,

    date(AddMonths(StartDate,IterNo()-1), 'YYYYMM') as StartDate,

    EndDate

Resident Temp

while EndDate - addmonths(StartDate, IterNo()-1) >= 0;

DROP TABLE Temp;

I've also attached a working example.

Gysbert_Wassenaar

Something like this:

LOAD KeyName, date(addmonths(date#(StartDate,'YYYYMM'),IterNo()-1),'YYYYMM') as StartDate, EndDate

while addmonths(date#(StartDate,'YYYYMM'),IterNo()-1) <= date#(EndDate,'YYYYMM');

LOAD * INLINE [

    KeyName, StartDate, EndDate

    XYZ, 201307, 201309

    BBB, 201308, 201309

    CCC, 201312, 201402

];

The inline load is just an example to load your sample data. You can replace it with something else that loads data from a file or database.


talk is cheap, supply exceeds demand
MK_QSL
MVP
MVP

Not applicable
Author

Thanks it is working perfect

Nicole-Smith

I'm glad it's working for you!