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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

MaxDate and Max time selecting the data

Data looks like below

DocumentNoDateTimeStatus
11120090326131022STAT1
11120090326130907STAT2
11120081123112200STAT3
11120081122102000STAT4


I have to find the latest status of the document - that is

11120090326131022STAT1




tmp:

Load * from c:\file.xls;

Tmp1:

Load document,

Max(Date) as Udate,

Max(Time) as Utime

resident tmp

group by document ;

is working fine and it is picking only one value.

If I include the Status - it is picking the multiple records.For reporting I would like to show only the Latest value



11120090326131022STAT1


Is their any way to pickup the max date and time along with status.

Advance thanks for your help.

6 Replies
johnw
Champion III
Champion III

Here's one approach. Load in your table sorting by DocumentNo, then Date and Time descending. Whenever the DocumentNo changes (compare to previous(DocumentNo)), set a flag to 1, else null. Then inner join to an inline table with the flag set to 1. Drop the flag.

There's probably a way to do it in a single load without the inner join, but I'm not thinking of it. I'm probably missing something obvious, and am about to be publically humiliated. 😉

And while it won't cause problems for my proposed approach, note that max(Date) + max(Time) is not the same thing as max(Date + Time). It only works in your example because your times increase along with your dates.

disqr_rm
Partner - Specialist III
Partner - Specialist III

Would this work for you?

load
date(max(timestamp#(Date & ' ' & Time, 'YYYYMMDD hhmmss'))) as MaxDate,
time(max(timestamp#(Date & ' ' & Time, 'YYYYMMDD hhmmss'))) as MaxTime,
maxstring(dual(Status, timestamp#(Date & ' ' & Time, 'YYYYMMDD hhmmss'))) as MaxStatus
resident tmp
group by 1;

Not applicable
Author

Hi,

what you can also do is to sort your table and use PEEK.

ActualStatus:
Load
DocumentNo,
Date as ActualDate,
Time as ActualTime,
Status as ActualStatus
Resident TempStatus
Where DocumentNo <> Peek(DocumentNo)
Order By DocumentNo, Date DESC, Time DESC;

See the attached example.

Rainer

johnw
Champion III
Champion III


John witherspoon wrote:There's probably a way to do it in a single load without the inner join, but I'm not thinking of it. I'm probably missing something obvious, and am about to be publically humiliated. 😉


Rainer Filoda wrote:Where DocumentNo <> Peek(DocumentNo)

Yeah, there we go. That's the obvious solution I was missing. 🙂

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


Rainer Filoda wrote:Where DocumentNo <> Peek(DocumentNo)
Order By DocumentNo, Date DESC, Time DESC;


Nice solution!

-Rob

disqr_rm
Partner - Specialist III
Partner - Specialist III

wow! pretty cool solution Rainer. Thanks for the idea.

Rakesh