Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Duplicate a row and change values

Hi guys,

I have this table that is in my database,

Claim #Work Order #Arrival DateService Complete Date
14525129511/24/201401/21/2015
14625129603/22/20155/10/2015
14725129701/30/201502/30/2015


I need broke the months in rows like this, each row will be a month

Claim #Work Order #Arrival DateService Complete Date
14525129511/24/201411/30/2015
14525129512/01/1412/31/2015
14525129501/01/1401/21/2015
14625129603/22/201503/31/2015
14625129604/01/201504/30/2015
14625129605/01/201505/10/2015
14725129701/30/201501/31/2015
14725129702/01/201502/30/2015

My question is, how can I do that in my script?

Directory;

LOAD [Claim #],

     [Work Order #],

     [Arrival Date],

     [Service Complete Date]

FROM

Test.xlsx

(ooxml, embedded labels, table is Plan1);

Thanks.

1 Solution

Accepted Solutions
anbu1984
Master III
Master III

SET MonthDiff = Num(((year($2) * 12) + month($2)) - (((year($1) * 12) + month($1))) + 1);

SET DateFormat='MM/DD/YYYY';

Load Claim,[Work Order],If(IterNo()=1,[Arrival Date],

Date(MonthStart(AddMonths([Arrival Date],IterNo()-1)))) As [Arrival Date],

If(IterNo()=IterNo,[Service Complete Date],

Date(MonthEnd(AddMonths([Arrival Date],IterNo()-1)))) As [Service Complete Date]

While IterNo() <= IterNo ;

Load *,$(MonthDiff([Arrival Date],[Service Complete Date])) As IterNo;

Load Claim,[Work Order],Date#([Arrival Date],'MM/DD/YYYY') As [Arrival Date],Date#([Service Complete Date],'MM/DD/YYYY') As [Service Complete Date] Inline [

Claim,Work Order,Arrival Date,Service Complete Date

145,251295,11/24/2014,01/21/2015

146,251296,03/22/2015,5/10/2015

147,251297,01/30/2015,02/28/2015 ];

View solution in original post

5 Replies
anbu1984
Master III
Master III

SET MonthDiff = Num(((year($2) * 12) + month($2)) - (((year($1) * 12) + month($1))) + 1);

SET DateFormat='MM/DD/YYYY';

Load Claim,[Work Order],If(IterNo()=1,[Arrival Date],

Date(MonthStart(AddMonths([Arrival Date],IterNo()-1)))) As [Arrival Date],

If(IterNo()=IterNo,[Service Complete Date],

Date(MonthEnd(AddMonths([Arrival Date],IterNo()-1)))) As [Service Complete Date]

While IterNo() <= IterNo ;

Load *,$(MonthDiff([Arrival Date],[Service Complete Date])) As IterNo;

Load Claim,[Work Order],Date#([Arrival Date],'MM/DD/YYYY') As [Arrival Date],Date#([Service Complete Date],'MM/DD/YYYY') As [Service Complete Date] Inline [

Claim,Work Order,Arrival Date,Service Complete Date

145,251295,11/24/2014,01/21/2015

146,251296,03/22/2015,5/10/2015

147,251297,01/30/2015,02/28/2015 ];

sujeetsingh
Master III
Master III

What is your rule to repeat this rows

Not applicable
Author

Thanks for the reply Anbu,

How can I use this dynamically and load the data from my database?

LOAD [Claim #],

     [Work Order #],

     [Arrival Date],

     [Service Complete Date]

FROM

Test.xlsx

(ooxml, embedded labels, table is Plan1);

anbu1984
Master III
Master III

Replace Inline load by Excel

Replace this

Load Claim,[Work Order],Date#([Arrival Date],'MM/DD/YYYY') As [Arrival Date],Date#([Service Complete Date],'MM/DD/YYYY') As [Service Complete Date] Inline [ 

Claim,Work Order,Arrival Date,Service Complete Date 

145,251295,11/24/2014,01/21/2015 

146,251296,03/22/2015,5/10/2015 

147,251297,01/30/2015,02/28/2015 ];

By

Load Claim,[Work Order],Date#([Arrival Date],'MM/DD/YYYY') As [Arrival Date],Date#([Service Complete Date],'MM/DD/YYYY') As [Service Complete Date]

FROM

Test.xlsx

(ooxml, embedded labels, table is Plan1);

Not applicable
Author

Excelent Anbu,

Works Perfectly!