Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
alvinford
Contributor III
Contributor III

Derive New Field

Hi All,

I have the following table sorted by DateAndTime field and can be grouped by IDLOC column.

IDLOCDateAndTimeUpdatedDateandTime
P0120131120080000
P012013112008300020131120150000
P0120131121090000
P0320131201100000
P032013120114000020131202030000
P0320131201190000

My requirement is I need to compare the UpdatedDateandTime with DateAndTime i.e. UpdatedDateandTime has to be  compared with

Previous(DateAndTime), DateAndTime and Next(DateAndTime)  for the same group IDLOC. Based on the comparision need to derive New Field indicating the Flag.

If the UpdatedDateandTime is Greater Than DateAndTime then 1 else 0. After deriving the table will be as below.

IDLOCDateAndTimeUpdatedDateandTimeNewField
P0120131120080000
P0120131120083000201311201500001
P0120131121090000
P0320131201100000
P0320131201140000201312020300000
P0320131201190000

Thanks in Advance..

Regards,

Alvin.

12 Replies
sivarajs
Specialist II
Specialist II

if(num(DateAndTime)>num(UpdatedDateandTime),0,1)

Not applicable

First convert your date fields into Timestamps and then compare. Please try like below:

IF(NUM(TIMESTAMP#(DateAndTime,'YYYYMMDDhhmmss')) > NUM(TIMESTAMP#(UpdatedDateandTime,'YYYYMMDDhhmmss')) , 0 ,1) AS NewField

alvinford
Contributor III
Contributor III
Author

Hi Dathu,

Thanks for your reply.

I want to compare with the Previous and Next  and Same row , if I do as suggested by you , it will only compare the same row. Which is not my requirement.

Regards,

Alvin.

Not applicable

You can to use the functions "below" and "above" for to valuate the preceeding and following row.

Regards

Ciro

saumyashah90
Specialist
Specialist


You can use previous function in Script

if(Num(TIMESTAMP#(UpdatedDateandTime,'YYYYMMDDhhmmss'))=Previous(NUM(TIMESTAMP#(DateAndTime,'YYYYMMDDhhmmss'))),1,0) as NewField

alvinford
Contributor III
Contributor III
Author

Hi Saumya

Thanks for your reply.

I want to compare with the Previous and Next  and Same row , if I do as suggested by you , it will only compare the same row. Which is not my requirement.

Regards,

Alvin.

Not applicable

Please, see the attachment
I hope reply your problem with solution...

Regards

alvinford
Contributor III
Contributor III
Author

Hi Ciro,

Thank you for your valuable reply. The solution which you have provided is correct, but i want to perform at the script level as I want to use the field for other calculation.

Regards,

Alvin.

Not applicable

Well, see now the attachment...