Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
fred_s
Partner - Creator III
Partner - Creator III

Generate table with several ranges

I've got a table like this:

pstart

pend

pdesc

1

3

car

10

12

van

15

16

truck



This table differs per customer.

Anyone suggestions how to rebuild this table like;

1 car
2 car
3 car
10 van
11 van
12 van
15 truck
16 truck

Thanks in advance.

1 Solution

Accepted Solutions
Not applicable

hi fred,

pls check the attached application

it shud work

thanks

View solution in original post

5 Replies
Not applicable

hi fred,

pls check the attached application

it shud work

thanks

boorgura
Specialist
Specialist

Get the count of pdesc.

Then use 2 FOR loops to loop through each pdesc and assign all the numbers between pstart and pend to it.

In the inner loop - use concatenate LOAD.

Let me know if it works.

fred_s
Partner - Creator III
Partner - Creator III
Author

Hi Tauqueer,

Thanks! Just what I had in mind.

Rocky thanks for thinking along!

Tauqueer, I hope you don't mind to share your script with others, so others can view your solution without downloading the qvw.


mt:
LOAD * INLINE [
pstart, pend, pdesc
1, 3, car
10, 12, van
15 , 16, truck
];
let x=noofrows('mt');
for i=1 to $(x)
let y=fieldvalue('pstart',$(i));
let z=fieldvalue('pend',$(i));
for j= $(y) to $(z)
load $(j) as column1,fieldvalue('pdesc',$(i)) as column2 resident mt;
next j
next i


johnw
Champion III
Champion III

It's simpler and I suspect faster with a WHILE loop:

mt:
LOAD * INLINE [
pstart, pend, pdesc
1, 3, car
10, 12, van
15 , 16, truck
];
LEFT JOIN (mt)
LOAD *,pstart+iterno()-1 as pval
RESIDENT mt
WHILE pstart+iterno()-1 <= pend
;

fred_s
Partner - Creator III
Partner - Creator III
Author

Hi John,

Sounds like you know the answer to just any question.
Your solution is even better.

Thanks, you're a great help to this Community.


Fred