Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Amelia_96
Contributor III
Contributor III

Sort by the timestamp and select only the last status for each ID

Hi, i'm trying to sort my data according to the timestamp in qlikview script. Then i want to select only the last status for each ID. How can i write this in the script?

Here's my sample data:

Amelia_96_0-1605094388275.png

And the expected output:

Amelia_96_1-1605094488381.png

Thank you in advance!!

3 Solutions

Accepted Solutions
QFabian
Specialist III
Specialist III

Hi, try this :

X:

Load 

   ID,

    max(Timestamp)  as MaxTimeStamp

From yor source

   group by ID;

 

left join

Load

ID,

Timestamp as MaxTimeStamp,

Status as LastStatus

Resident yuour source;

 

QFabian

View solution in original post

tresesco
MVP
MVP

@Amelia_96    Try like:

Load

     ID,

     Timestamp(Max(Timestamp)) as Timestamp,

     FirstSortedValue(Status, -Timestamp) as Status

From <> Group by ID;

View solution in original post

edwin
Master II
Master II

another option, create a chart with only calculated dimensions (replace Date with timestamp):

edwin_0-1605098533636.png

 

View solution in original post

8 Replies
QFabian
Specialist III
Specialist III

Hi, try this :

X:

Load 

   ID,

    max(Timestamp)  as MaxTimeStamp

From yor source

   group by ID;

 

left join

Load

ID,

Timestamp as MaxTimeStamp,

Status as LastStatus

Resident yuour source;

 

QFabian
QFabian
Specialist III
Specialist III

This is how i transformed the text field to a valid timestamp :


MonthX:
mapping
LOAD * INLINE [
F1, F2
JAN, 1
FEB, 2
MAR, 3
APR, 4
MAY, 5
JUN, 6
JUL, 7
AUG, 8
SEP, 9
OCT, 10
NOV, 11
DEC, 12
];

 

TIMESTAMP:
LOAD * INLINE [
TIMESTAMP
03FEB2020 :16:42:36
];


Load
makedate(right(subfield(TIMESTAMP, ' ' ,1), 4) , applymap('MonthX',mid(subfield(TIMESTAMP, ' ' ,1), 3,3)), left(subfield(TIMESTAMP, ' ' ,1), 2)) + mid(subfield(TIMESTAMP, ' ' ,2),2) as TIMESTAMP2,
mid(subfield(TIMESTAMP, ' ' ,2),2) as hora
Resident TIMESTAMP;

QFabian_0-1605097443950.png

 

 

QFabian
tresesco
MVP
MVP

@Amelia_96    Try like:

Load

     ID,

     Timestamp(Max(Timestamp)) as Timestamp,

     FirstSortedValue(Status, -Timestamp) as Status

From <> Group by ID;

edwin
Master II
Master II

another option, create a chart with only calculated dimensions (replace Date with timestamp):

edwin_0-1605098533636.png

 

edwin
Master II
Master II

forgot to mention in your dimensions, set SUPPRESS WHEN VALUE IS NULL

Amelia_96
Contributor III
Contributor III
Author

Thank you @edwin 

Amelia_96
Contributor III
Contributor III
Author

Thank you @QFabian 

Amelia_96
Contributor III
Contributor III
Author

Thank you @tresesco