Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Create duplicate records for fields with ranges

Hi all,

I  have a table with range data and I want to create separate rows for each value int he range.

Example:

Input file:

Field A          Field B

20                    INC1234

30                    INC1239

40                    INC1240-INC1250

Expected result:

Field A          Field B

20                    INC1234

30                    INC1239

40                    INC1240

40                    INC1241

40                    INC1242

40                    INC1243

40                    INC1244

40                    INC1245

40                    INC1246

40                    INC1247

40                    INC1248

40                    INC1249

40                    INC1250

thanks

1 Solution

Accepted Solutions
maxgro
MVP
MVP

RESULT

1.png

SCRIPT

Source:

load

FieldA, FieldB,

replace(SubField(FieldB, '-', 1),'INC','') as From,

if(Index(FieldB,'-')=0, replace(FieldB,'INC',''), replace(SubField(FieldB, '-', 2),'INC','')) as To;

load * inline [

FieldA,          FieldB,

20    ,                INC1234

30    ,                INC1239

40    ,                INC1240-INC1250

];

Table:

load

FieldA,

FieldB,

From,

To,

From + IterNo()-1 as New

Resident Source

while IterNo() <= To - From + 1

;

DROP Table Source;

View solution in original post

2 Replies
maxgro
MVP
MVP

RESULT

1.png

SCRIPT

Source:

load

FieldA, FieldB,

replace(SubField(FieldB, '-', 1),'INC','') as From,

if(Index(FieldB,'-')=0, replace(FieldB,'INC',''), replace(SubField(FieldB, '-', 2),'INC','')) as To;

load * inline [

FieldA,          FieldB,

20    ,                INC1234

30    ,                INC1239

40    ,                INC1240-INC1250

];

Table:

load

FieldA,

FieldB,

From,

To,

From + IterNo()-1 as New

Resident Source

while IterNo() <= To - From + 1

;

DROP Table Source;

Not applicable
Author

thanks