Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
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
MVP
MVP

Re: how to concatenate and compute new column

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

Re: how to concatenate and compute new column

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

Sector0:

LOAD *,

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

MVP
MVP

Re: how to concatenate and compute new column

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

Re: how to concatenate and compute new column

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);

MVP
MVP

Re: how to concatenate and compute new column

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);

Re: how to concatenate and compute new column

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.

MVP
MVP

Re: how to concatenate and compute new column

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.

Community Browser