Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
giovanni16
Contributor
Contributor

Add rows in table between start and enddate

Hi all,

Can someone help me with the right script for creating/adding rows in table based on start and end date.

I want to have a row for each record from the start date till the end date for the number of months. So I can create a table of the monthvalues for each contract record in time.

It is probably simple, but as a beginner, any help will be appreciated.

Thank you.

1 Solution

Accepted Solutions
15 Replies
maxgro
MVP
MVP

giovanni16
Contributor
Contributor
Author

Massimo,

Thank you for your answer.

However, what I want to achieve is to have one row for each month, instead of for each day. I tried to change the amounts in amount per day, but it gives a difference in the months. Tried to change the Date() into Month(), but with no result.

Is it possible to create only the rows for every first day of the month?

Thank you.

maxgro
MVP
MVP

maybe adding a filter (bold)?

t:

LOAD

  rowno() as id,

  diff,

     start,

     end,

     endmonth,

     connr,

     [amount pm]

FROM File.xls

(biff, embedded labels, table is Sheet1$)

;

u:

load   *

where day(newdate)=1;              

load id,

date(start + iterno()-1) as newdate

Resident t

While start + IterNo()-1 <= end;

giovanni16
Contributor
Contributor
Author

Hi Massimo,

I tried, not working.

What I need is:  Each row is uniek. I need to multiply it by the number in the column DIFF (month difference) and create as many rows.

For each row 1 month... (it should be the first date of the month)

Thank you in advance..

maxgro
MVP
MVP

this?

top table is your source data (first record only)

bottom is the output: one record for every month between start / end fields (mar-2015....dic-2017)

1.jpg

giovanni16
Contributor
Contributor
Author

Massimo,

Yes. That is what I need to achieve.  How?

Anonymous
Not applicable

Hi,

Please use below script:

Set DateFormat = 'DD/MM/YYYY';


Data:
LOAD * INLINE
[
Date
26/07/2011
29/09/2011
13/12/2011
]
;

LOAD Date,
Year(Date) as Year,
Month(Date) as Month,
Date(Date,'MMM/YYYY') as MonthYear,
Monthname(Date) as MonthName;
Load Date(MinDate + IterNo() -1 ) AS Date While (MinDate + IterNo() - 1) <= Num(MaxDate);
Load
Min(Date) AS MinDate,
Max(Date) AS MaxDate
RESIDENT Data;

Regards

Neetha

Anonymous
Not applicable

You can modify to your requirement:

Load
Min(Start date) AS MinDate,
Max(end date) AS MaxDate
RESIDENT Data;

maxgro
MVP
MVP

PFA