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: 
Not applicable

how to concatenate and compute new column

Hi,

I want to concatenate 2 tables with the same column names and compute new columns from existing columns. If I do this:

Sector0:

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time,

     Date([Date Confirmed],'M/D/YYYY') as [Actual Date],

     If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

     If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]

FROM

<file>

(txt, codepage is 1252, embedded labels, delimiter is '|', msq);


Concatenate(Sector0)

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time,

     Date([Date Confirmed],'M/D/YYYY') as [Actual Date],

     If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

     If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]

FROM

<file2>

(biff, embedded labels, table is Sheet1$);

there will be the error messages "Field not found - <Time>" and "Table not found Concatenate(Sector0)...".

But if the code is like the one below, the script can successfully load.

Sector0:

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time,

     Date([Date Confirmed],'M/D/YYYY') as [Actual Date]

FROM

<file>

(txt, codepage is 1252, embedded labels, delimiter is '|', msq);

Concatenate(Sector0)

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time,

     Date([Date Confirmed],'M/D/YYYY') as [Actual Date],

     If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

     If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]

FROM

<file2>

(biff, embedded labels, table is Sheet1$);

Thanks.

Rachel

7 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi,

In First table do you have column named Time in the table?  If there is no Time column then you will get this error.

Regards,

Jagan.

Not applicable
Author

Yes, I created a Time column in the first table Sector0

Sector0:

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time

jagan
Luminary Alumni
Luminary Alumni

Hi,

The error is because of this two lines

If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

     If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]


In that Time is used as a Column, it should be like this


Sector0:

LOAD

*,

If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

     If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm];

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time,

     Date([Date Confirmed],'M/D/YYYY') as [Actual Date]    

FROM

<file>

(txt, codepage is 1252, embedded labels, delimiter is '|', msq);


Regards,

Jagan.



Not applicable
Author

Ok. But i have another column to add and if I put this, it does not work.

There is this error message "Field not found - <Before 10am>

LOAD

*,

     If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

     If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm],

     If([Before 10am]+[After 10pm]>0,'Night Shift','Day Shift') as Shift;

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time,

     Date([Date Confirmed],'M/D/YYYY') as [Actual Date]  

FROM

<file>

(txt, codepage is 1252, embedded labels, delimiter is '|', msq);

maxgro
MVP
MVP

add another load (below, not bold)

load

          *,

          If([Before 10am]+[After 10pm]>0,'Night Shift','Day Shift') as Shift;

LOAD

*,

     If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

     If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]

     // If([Before 10am]+[After 10pm]>0,'Night Shift','Day Shift') as Shift;

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time,

     Date([Date Confirmed],'M/D/YYYY') as [Actual Date] 

FROM

<file>

(txt, codepage is 1252, embedded labels, delimiter is '|', msq);

MarcoWedel

to sum it up, you can't use a field name in the same load where it is created (as well as e.g. in it's where clause).

Use preceding loads in these cases.

jagan
Luminary Alumni
Luminary Alumni

Hi,

In the top load statement you dont have [Before 10am] and [After 10pm] columns, that is why you are getting the errrors.

Try this

LOAD

*,

     If([Before 10am]+[After 10pm]>0,'Night Shift','Day Shift') as Shift;

LOAD

*,

     If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

     If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm];

LOAD *,

     Time([Date Confirmed],'hh:mm:ss') as Time,

     Date([Date Confirmed],'M/D/YYYY') as [Actual Date] 

FROM

<file>

(txt, codepage is 1252, embedded labels, delimiter is '|', msq);

Regards,

Jagan.