Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

kchuying
New Contributor II

Duplicate rows based on field quantity

Dear all,

I have a table as shown below.

  

CodeQty
A0011
A0021
B0012
B0023

I am trying to achieve the breakdown of quantity to 1 unit per row.

How do I go about using a 'for loop' to duplicate the records? Or suggest any better methods.

  

CodeQty
A0011
A0021
B0011
B0011
B0021
B0021
B0021

The above is just a simple example. There could be multiple fields.

Thanks in advance!

Tags (1)
3 Replies

Re: Duplicate rows based on field quantity

May using While loop...

LOAD Code,

     1 as Qty

FROM ...

While IterNo() <= Qty;

Re: Duplicate rows based on field quantity

Here is a sample script using Inline load

LOAD RowNo() as RowNum,

Code,

1 as Qty

While IterNo() <= Qty;

LOAD * INLINE [

    Code, Qty

    A001, 1

    A002, 1

    B001, 2

    B002, 3

];


Capture.PNG

Re: Duplicate rows based on field quantity

I think both of you are working in the same/similar project/office as you both have same question.

How to skip values in for .. next  loops

Community Browser