Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikviewalex
Contributor III
Contributor III

Load only min date and time with key

Hello,

I load a Table.

Tasks:

LOAD [Object-ID],

     Key,

     Date,

     Time,

     Text

FROM  test.xlsx (ooxml, embedded labels, table is table1);


This Table looks like this:

   

KeyDateTimeText
Key202.01.201709:17:14b
Key104.01.201710:01:52d
Key101.01.201700:13:00a
Key107.01.201700:57:38g
Key306.01.201701:42:17f
Key208.01.201702:26:55h
Key309.01.201703:11:34i
Key303.01.201703:56:12c
Key205.01.201704:40:50e

now I need a table with only the first Timestamp (Date+Time) for a Key.

I Order the Table.

...order by Key, Date, Time;

   

KeyDateTimeText
Key101.01.201700:13:00a
Key104.01.201700:57:38d
Key107.01.201701:42:17g
Key202.01.201709:17:14b
Key205.01.201710:01:52e
Key208.01.201710:46:31h
Key303.01.201711:31:09c
Key306.01.201712:15:48f
Key309.01.201713:00:26i

Now I need only the first row per key.

   

KeyDateTimeText
Key101.01.201700:13:00a
Key202.01.201709:17:14b
Key303.01.201710:01:52c

Unfortunately, I have no idea how I can do this reshaping.

I hope someone can help me.

Alex

11 Replies
Not applicable

Hi,

Took me a while to understand Treseco B approach

Now I figured it out. "Final" table is sorted by key and timestamp and "not exists" function acts as "distinct" there. So it takes only first occurency of Key1, Key2, Key3 etc. which are sorted by timestamp in previous step.

Nice thinking and very useful tip. I used a lot of max/min/peek functions but this is really smart. Especially when you have more fields in your load.

Thanks!

BR,

Milosz

vinieme12
Champion III
Champion III

instead of Joining we can also use Right Keep  and this would be faster than using Exist

Tasks:

load Key,timestamp(timestamp#(Date&' '&Time,'DD.MM.YYYY hh:mm:ss')) as datetime,Date,Time,Text;

load * inline [

Key, Date, Time, Text, 

Key2, 02.01.2017, 09:17:14, b

Key1, 04.01.2017, 10:01:52, d

Key1, 01.01.2017, 00:13:00, a

Key1, 07.01.2017, 00:57:38, g

Key3, 06.01.2017, 01:42:17, f

Key2, 08.01.2017, 02:26:55, h

Key3, 09.01.2017, 03:11:34, i

Key3, 03.01.2017, 03:56:12, c

Key2, 05.01.2017, 04:40:50, e

  ];

Right keep

Tasks2:

LOAD Key,min(datetime) as datetime

Resident Tasks

group by Key ;

Drop table Tasks2

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.