Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to use if then statement to create new column

Hi, how do i create a column called 'before 10am' using if then statement? The underlined part has error.

LOAD * INLINE [

    Before 10am

];

if([Time]<='10:00:00') then ([Before 10am]=1);

Thanks.

8 Replies
jsingh71
Partner - Specialist
Partner - Specialist

try this

if([Time] <= '10:00:00',([Before 10am]=1))

tresesco
MVP
MVP

Do you want the value of the field to be set '1' or '0', if so then try like:

load

       If( yourcondition, 1,0) as [Before 10am]

alexandros17
Partner - Champion III
Partner - Champion III

MYTAB:

LOAD * INLINE [

    Name

     John

     Luis

     Alex

];

Load

     *,

     if(Name = 'Alex', 'Alex The Great', Name) as newName

resident MYTAB;

Drop Table MYTAB;

Hope it helps

preminqlik
Specialist II
Specialist II

elaborate the question , i think you need to create a coumn in front end or backend then you directly use maketime(hh,m,ss)

like below :

in script:

if([Time]<=maketime(10,0,0) ,1,0)               as               Before10am

or 

in front end expression :

if([Time]<=maketime(10,0,0) ,1,0)

Not applicable
Author

Sorry, none of the answers worked. I want the column 'before 10am' to be 1 if the column 'time' is >=10:00:00, else it will be 0. Thanks.

Not applicable
Author

Hi,

Try this..

Load

if(Timestamp(time,'hh:dd:ss')>'10:00:00',1,0) as [before 10am]

From <YourTable> ;

Thanks,

Prabhu

anbu1984
Master III
Master III

If( Time >= '10:00:00' , 1,0) as [Before 10am]

rbecher
MVP
MVP

Hi Rachel,

I would use:

LOAD

if( time#([Time], 'hh:mm:ss') < time#('10:00:00', 'hh:mm:ss'), 'Before 10am') as TimeBefore10am

...

FROM

- Ralf

Astrato.io Head of R&D