Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Talk to Experts, a LIVE Q&A Webinar. Bring your Qlik Sense Business questions on Aug. 4th. Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator
Creator

Load latest timestamp, from dates.

Hi

I think I have read every community thread I could find about this, and no solution I found solves my problem. 

I need to extract the latest timestamp from every date in my table. 

LOAD * INLINE [
    ID, TimeStamp, Value
555,	31-10-2019 23:15,	500
555,	31-10-2019 23:30,	100
555,	31-10-2019 23:46,	100 //I need this value
555,	01-11-2019 00:01,	100
555,	01-11-2019 00:17,	100
555,	01-11-2019 00:32,	100
555,	01-11-2019 00:48,	100
555,	01-11-2019 01:03,	100
555,	01-11-2019 01:19,	100
555,	01-11-2019 01:34,	100
555,	01-11-2019 01:50,	100
555,	01-11-2019 02:05,	100
555,	01-11-2019 02:21,	100
555,	01-11-2019 02:36,	100 //I need this value

];

 

I need a way to only load the Max(Timestamp) from each date.

1 Solution

Accepted Solutions
Highlighted
Contributor III
Contributor III

Re: Load latest timestamp, from dates.

I think, grouping clause is missing at the second load statement

"Group by SensorID, date"

View solution in original post

7 Replies
Highlighted

Re: Load latest timestamp, from dates.

In the script/design?

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
Highlighted
Creator
Creator

Re: Load latest timestamp, from dates.

Sorry. 

I want to do it in the Load script. 

Highlighted
MVP
MVP

Re: Load latest timestamp, from dates.

SET TimestampFormat='DD-MM-YYYY hh:mm';
SET DateFormat='DD-MM-YYYY';

LOAD
  Date,
  TimeStamp(Max(TimeStamp)) AS LatestTimeStamp,
  FirstSortedValue(Value,-TimeStamp) AS Value
GROUP BY
  Date;
LOAD
  *,
  Date(Floor(TimeStamp)) AS Date
INLINE [

  ID, TimeStamp, Value
  555, 31-10-2019 23:15, 500
  555, 31-10-2019 23:30, 100
  555, 31-10-2019 23:46, 100, //I need this value
  555, 01-11-2019 00:01, 100
  555, 01-11-2019 00:17, 100
  555, 01-11-2019 00:32, 100
  555, 01-11-2019 00:48, 100
  555, 01-11-2019 01:03, 100
  555, 01-11-2019 01:19, 100
  555, 01-11-2019 01:34, 100
  555, 01-11-2019 01:50, 100
  555, 01-11-2019 02:05, 100
  555, 01-11-2019 02:21, 100
  555, 01-11-2019 02:36, 100, //I need this value
];

 

or like this:

 
LOAD
  Date,
  TimeStamp(Max(TimeStamp)) AS LatestTimeStamp,
  FirstSortedValue(Value,-TimeStamp) AS Value
GROUP BY
  Date;
LOAD
  *,
  Date(Floor(TimeStamp)) AS Date
FROM
  SourceFile.txt (txt);

 

Highlighted
MVP & Luminary
MVP & Luminary

Re: Load latest timestamp, from dates.

You could try it with this:

t: load *, date(floor(Timestamp)) as D, time(frac(Timestamp)) as t from Source;
    inner join(t) load ID, D, max(t) as t resident t;

- Marcus

Highlighted
Creator
Creator

Re: Load latest timestamp, from dates.

I am getting an error when trying to use this solution: 

 

Temp:
LOAD
    @2 as SensorID,
	date(floor(@3)) as date,
    time(frac(@3)) as time,
    @10  as value
    
FROM [lib://Co2/Co2Sensor_201911.csv]
(txt, codepage is 28591, no labels, delimiter is ';', msq, header is 1 lines) where IsNum(@2) and @2<>23000290 and @11<101 and @3>=today()-200;;

Temp2:
inner join(Temp)
load 
	SensorID, 
	date, 
    max(time) as time 
resident Temp;

Drop Table Temp;
Highlighted
Contributor III
Contributor III

Re: Load latest timestamp, from dates.

I think, grouping clause is missing at the second load statement

"Group by SensorID, date"

View solution in original post

Highlighted
Creator
Creator

Re: Load latest timestamp, from dates.

This was the final solution with the help from @marcus_sommer and @cengizeralp (thx guys)

Temp:
LOAD
    @2 as SensorID,
	date(floor(@3)) as date,
    time(frac(@3)) as time,
    @10  as value
    
FROM [lib://Co2/Co2Sensor_201911.csv]
(txt, codepage is 28591, no labels, delimiter is ';', msq, header is 1 lines) where IsNum(@2) and @2<>23000290 and @11<101 and @3>=today()-200;;

inner join(Temp)
load 
	SensorID, 
	date, 
    max(time) as time 
resident Temp group by SensorID, date;