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
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi Rachel,

you could use this expression:

if(hour([timefield]) < 10, 1, 0) as [before 10 am]

Marcus

anbu1984
Master III
Master III

Why did you start duplicate thead?

Original thread: How to use if then statement to create new column

manideep78
Partner - Specialist
Partner - Specialist

Try this in the script

If(Your_Column_Name<10:00:00 ,1, 0) as New_Column

Make sure you give the Appropriate date format in the condition above,

Hope this helps you.

Regards,

Manideep.

Not applicable
Author

Thanks, but apparently I cant put comma no matter what I do...

manideep78
Partner - Specialist
Partner - Specialist

Please check whether the date format is appropriate or not.

if you are writing if condition in preceding load make sure you put semicolon at the end.

Eg:

Load *, if(condition) as New_Column;

Load

A,

B,

C

From <Path>

Or else post your script in which you need the condition.

lukaspuschner
Partner - Creator
Partner - Creator

i think this will work:

if(Time(YourField)<MakeTime(10),1,0)

Not applicable
Author

This is my script:

LOAD * INLINE [

    Before 10am,

];

if([Time])<10:00:00,1,0) as [Before 10am];

The underlined colon after '10' has error. Thanks.

Not applicable
Author

Hey thanks for your answer, but the comma after (10) has error.

manideep78
Partner - Specialist
Partner - Specialist

Try this

LOAD *, if(Hour(Timestamp(Time,'hh:mm:ss'))<10,1,0) as before10am;

LOAD * Inline [

Time

10:00:00,

11:00:00,

9:00:00

];

This should work