Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
shekhar_analyti
Specialist
Specialist

How to repeat number of rows X times during load based where value of X is in one of the field ?

Hi All ,

This is my first post , post community modification .

Problem :

How to repeat number of rows X times during load based where value of X is in one of the field ?

 

INPUT 

LOAD * INLINE [
Year, ID, Country, Sales, MARK
2015, EMPID001, CHINA, 200, 1
2016, EMPID002, RUSSIA, 50, 3              - Repeat it three times starting with 1 ending 3 
2017, EMPID003, INDIA, 400, 4                -   Repeat it four times starting with 1 ending 4
2018, EMPID004, US, 600, 1
];

 

OUTPUT 

YearIDCountrySalesNew_Mark
2015EMPID001CHINA2001
2016EMPID002RUSSIA501
2016EMPID002RUSSIA502
2016EMPID002RUSSIA503
2017EMPID003INDIA4001
2017EMPID003INDIA4002
2017EMPID003INDIA4003
2017EMPID003INDIA4004
2018EMPID004US6001

 

Thanks & Regards

Shekar

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Try this:

MyTable:
LOAD *, IterNo() as New_Mark While Iterno() <= MARK; LOAD * INLINE [ Year, ID, Country, Sales, MARK 2015, EMPID001, CHINA, 200, 1 2016, EMPID002, RUSSIA, 50, 3 2017, EMPID003, INDIA, 400, 4 2018, EMPID004, US, 600, 1 ];

 


talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar

Try this:

MyTable:
LOAD *, IterNo() as New_Mark While Iterno() <= MARK; LOAD * INLINE [ Year, ID, Country, Sales, MARK 2015, EMPID001, CHINA, 200, 1 2016, EMPID002, RUSSIA, 50, 3 2017, EMPID003, INDIA, 400, 4 2018, EMPID004, US, 600, 1 ];

 


talk is cheap, supply exceeds demand
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Use below script;

 

Data:
LOAD *,'1-'&MARK as KEY INLINE [
Year, ID, Country, Sales, MARK
2015, EMPID001, CHINA, 200, 1
2016, EMPID002, RUSSIA, 50, 3
2017, EMPID003, INDIA, 400, 4
2018, EMPID004, US, 600, 1
];

Max:
Load Max(MARK) as MAX
Resident Data;

Let vMax = Peek('MAX',0,'Max');

Autogenerate:
Load RowNo() as Number
AutoGenerate $(vMax);

Interval:
IntervalMatch(Number)
Load '1' as Start,MARK as END
Resident Data;

Left join(Data)
Load Start&'-'&END as KEY,Number
Resident Interval;

Drop table Interval,Autogenerate;

 

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!