Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Looping with Concatenation

Hi All,

How the looping is done with concatenation.

As of now I am loading data as

Actual:

Load

Month1,

Year1,

KeyData

Resident Temp;

Conatenate

Load

Month2,

Year2,

KeyData

Resident Temp;

Conatenate

Load

Month3,

Year3,

KeyData

Resident Temp;

Conatenate

Load

Month4,

Year4,

KeyData

Resident Temp;

Can we write a Loop statement so that it loops for 4 times with concatenating the data so that my code size decreases?

1 Solution

Accepted Solutions
anbu1984
Master III
Master III

You missed ENDIF for second If statement

Temp:

LOAD * INLINE [

    Key, Week1, Week2,Week3, Act1, Act2, Act3, For1, For2, For3, Zero

    ABC, 1, 2, 3, 20, 30, 40, 20, 30, 40, Y

    BCD, 1, 2, 3, 20, 30, 40, 15, 30, 100

    DEF, 1, 2, 3, 20, 30, 40, 25, 50, 200

];

For i = 1 to 3

if ($(i)=1) then

Main:

Load

Key,

Week$(i) as Week,

Act$(i) as Act,

For$(i) as For,

Zero

Resident Temp;

ENDIF

if ($(i)>1) then

Concatenate

Main:

Load Key,

Week$(i) as Week,

Act$(i) as Act,

For$(i) as For

Resident Temp;

ENDIF

Next

Drop Table Temp;

View solution in original post

8 Replies
anbu1984
Master III
Master III

Temp:

LOad * Inline [

KeyData,Month1,Year1,Month2,Year2

1,Jan,2011,Feb,2012

2,Jan,2011,Feb,2012 ];

For I = 1 to 2

Temp1:

Load

Month$(I) As Month,

Year$(I) As Year,

KeyData

Resident Temp;

Next

Not applicable
Author

HI ,

What about concatenation?

anbu1984
Master III
Master III

If you have same field names, concatenation happens automatically

sujeetsingh
Master III
Master III

Temp:

LOad * Inline [

KeyData,Month1,Year1,Month2,Year2

1,Jan,2011,Feb,2012

2,Jan,2011,Feb,2012 ];

For I = 1 to 2

Concatenate

Load

Month$(I) As Month,

Year$(I) As Year,

KeyData

Resident Temp;

Next

Not applicable
Author

What If i want to load

Key, Month1, Year1 seperately and then Concatenate the Looping Table.?

Because While loading Key, Month1, Year1 I will load one more calculated field and that field will not have value to other rows.

Like below:

Load

Month1 As Month,

Year1 As Year,

KeyData,

X+y = Z

Resident Temp;

Concatenate

For I = 2 to 3

Load

Month$(I) As Month,

Year$(I) As Year,

KeyData

Resident Temp;

Next

anbu1984
Master III
Master III

Temp1:

Load

Month1 As Month,

Year1 As Year,

KeyData,

X+Y As Z

Resident Temp;

For I = 2 to 3

Concatenate

Load

Month$(I) As Month,

Year$(I) As Year,

KeyData

Resident Temp;

Next

Not applicable
Author

Am I doing some mistake?

I should Get only one table But

I am getting two tables with a SynTable.

Temp:

LOAD * INLINE [

    Key, Week1, Week2,Week3, Act1, Act2, Act3, For1, For2, For3, Zero

    ABC, 1, 2, 3, 20, 30, 40, 20, 30, 40, Y

    BCD, 1, 2, 3, 20, 30, 40, 15, 30, 100

    DEF, 1, 2, 3, 20, 30, 40, 25, 50, 200

];

For i = 1 to 3

if ($(i)=1) then

Main:

Load

Key,

Week$(i) as Week,

Act$(i) as Act,

For$(i) as For,

Zero

Resident Temp;

ENDIF

if ($(i)>1) then

Concatenate

Main:

Load Key,

Week$(i) as Week,

Act$(i) as Act,

For$(i) as For

Resident Temp;

Next

Drop Table Temp;

anbu1984
Master III
Master III

You missed ENDIF for second If statement

Temp:

LOAD * INLINE [

    Key, Week1, Week2,Week3, Act1, Act2, Act3, For1, For2, For3, Zero

    ABC, 1, 2, 3, 20, 30, 40, 20, 30, 40, Y

    BCD, 1, 2, 3, 20, 30, 40, 15, 30, 100

    DEF, 1, 2, 3, 20, 30, 40, 25, 50, 200

];

For i = 1 to 3

if ($(i)=1) then

Main:

Load

Key,

Week$(i) as Week,

Act$(i) as Act,

For$(i) as For,

Zero

Resident Temp;

ENDIF

if ($(i)>1) then

Concatenate

Main:

Load Key,

Week$(i) as Week,

Act$(i) as Act,

For$(i) as For

Resident Temp;

ENDIF

Next

Drop Table Temp;