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

how to use if then else statement to create new column?

Hi, how should the script be like if I want a column 'before 10am' to be 1 if the column 'time' is >=10:00:00, else it will be 0? Thanks.

13 Replies
anbu1984
Master III
Master III

What is the source for field Time?

Add quotes to time '10:00:00'

Not applicable
Author

The field 'time' is not found.

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

FROM

<file>

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

load *,If([Time]< Timestamp('10:00:00','hh:mm:ss'),1,0) as [Before 10am];

LOAD * INLINE [

    Before 10am,

];

Not applicable
Author

The time list box was created successfully with the data and all, but when the script reads it to create the 'before 10am' column, then the time field cannot be found.

manideep78
Partner - Specialist
Partner - Specialist

I did not understand why you are giving the Inline statement below the If condition. what is the necessary of it. Inline does not work here. you should take resident of the previous table in which time field exists.

Try like this.

T1:

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

FROM

<file>

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

T2:

LOAD *,If([Time]< Timestamp('10:00:00','hh:mm:ss'),1,0) as [Before 10am];

Resident T1;


This should work.