Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

hcavanhoogdalem
New Contributor III

For loops, start/end dates and keytables

Hi everyone,

I have the foloowing table (simplified of course):

CodeFROM_dateTO_dateManager
10001 - 01 - 201603 - 01 - 2016Hank
10101 - 01 - 201605 - 01 - 2016Edward

Now what i want to make is the following table

DAY-CODE-KEYManager
01-01-2016-100Hank
02-01-2016-100Hank
03-01-2016-100Hank
01-01-2016-101Edward
02-01-2016-101Edward
03-01-2016-101Edward
04-01-2016-101Edward
05-01-2016-101Edward

So basically i want to load each row in the top-table and then use a FOR-loop to create rows in a new table.

I was thinking to loop through the lines, then set two vars with peek (from and to), and then loop from 'from' to 'to' and create the lines in table 2.

Am I thinking in the wrong direction? Cause I can't seem to nest two for statements....

Kind regards,

Herb

1 Solution

Accepted Solutions

Re: For loops, start/end dates and keytables

Another options:

Intervals:

LOAD Date,

  Code,

  Date & '-' & Code as [DAY-CODE-KEY],

  Manager;

LOAD Date(FROM_Date + IterNo() - 1) as Date,

  Code,

  Manager

While FROM_Date + IterNo() - 1 <= TO_date;

Load * Inline [

FROM_Date, TO_date, Code, Manager

01-01-2016, 03-01-2016, 100, Hank

01-01-2016, 05-01-2016, 101, Edward

];


Capture.PNG

4 Replies
hod
New Contributor III

Re: For loops, start/end dates and keytables

Herb,

I think you can use the intervalmatch function. Take a look at this script and see if it can help you along the way.

best regards,

Helena

Re: For loops, start/end dates and keytables

Another options:

Intervals:

LOAD Date,

  Code,

  Date & '-' & Code as [DAY-CODE-KEY],

  Manager;

LOAD Date(FROM_Date + IterNo() - 1) as Date,

  Code,

  Manager

While FROM_Date + IterNo() - 1 <= TO_date;

Load * Inline [

FROM_Date, TO_date, Code, Manager

01-01-2016, 03-01-2016, 100, Hank

01-01-2016, 05-01-2016, 101, Edward

];


Capture.PNG

hcavanhoogdalem
New Contributor III

Re: For loops, start/end dates and keytables

Thanks, this time I chose the iterative solution provided by Sunny.

Thanks for the example of proper use of an interval function.

hcavanhoogdalem
New Contributor III

Re: For loops, start/end dates and keytables

Thanks, works exactly as needed.

Community Browser