Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Mr_small_t
Contributor III
Contributor III

New table with a calculated new variable

Hi

I guess this is simple, but I have to ask anyway. 

Question 1: 

In the attached spreadsheet you can see my Table_original. I have to loop through each  ID to see if Duration>1. If Duration is 2 i have to add 1 line, if Duration is 3 I have to add 2 lines, and so on. The result should be as in Table_new. 

Question 2:

I would like to create a variable IntSeries=(1,2,3,4,.....,100). What is the easiest way to create such a series?

 

Regards,

Torbjørn 

Labels (2)
1 Solution

Accepted Solutions
sunny_talwar

You can use While loop here

Table:
LOAD ID,
	 Yr_reg + IterNo() - 1 as Yr_reg,
	 Duration,
	 Level,
	 Code
While IterNo() <= Duration;
LOAD * INLINE [
    ID, Yr_reg, Duration, Level, Code
    23, 2016, 1, 1, K1
    23, 2017, 1, 2, K2
    23, 2018, 1, 3, K3
    23, 2019, 1, 4, K4
    23, 2020, 1, 5, K5
    25, 2016, 1, 1, S1
    25, 2018, 1, 2, S2
    25, 2019, 2, 3 and 4, S3
    27, 2017, 1, 1, K1
    27, 2019, 1, 3, K3
    28, 2020, 3, "3, 4, and 5", R3
];

View solution in original post

3 Replies
Brett_Bleess
Former Employee
Former Employee

Best I have for you is to have a look in the Design Blog area of Community where we have a bunch of how-to examples, that is likely the best place to get ideas on how to go about things.

https://community.qlik.com/t5/Qlik-Design-Blog/bg-p/qlik-design-blog

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
sunny_talwar

You can use While loop here

Table:
LOAD ID,
	 Yr_reg + IterNo() - 1 as Yr_reg,
	 Duration,
	 Level,
	 Code
While IterNo() <= Duration;
LOAD * INLINE [
    ID, Yr_reg, Duration, Level, Code
    23, 2016, 1, 1, K1
    23, 2017, 1, 2, K2
    23, 2018, 1, 3, K3
    23, 2019, 1, 4, K4
    23, 2020, 1, 5, K5
    25, 2016, 1, 1, S1
    25, 2018, 1, 2, S2
    25, 2019, 2, 3 and 4, S3
    27, 2017, 1, 1, K1
    27, 2019, 1, 3, K3
    28, 2020, 3, "3, 4, and 5", R3
];
Mr_small_t
Contributor III
Contributor III
Author

Thank you very much, mr. Sunny!!