Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Dud-As
Contributor
Contributor

Issue with dates

Hello everyone,

I have an Excel file with the following data:
-User Id
-Visit Date
-Visit Type (It is a number, with values from 1 to 5)

I need to get the one record for each user, for each type of visit and with the second most recent date (not the most recent visit, the previous one).

If I have the following data:
UserId VisitDate VisitType
1000 12/07/2021 1
1000 11/07/2021 2
1000 10/07/2021 1
1000 09/07/2021 2

I need as a result only:

1000 10/07/2021 1
1000 09/07/2021 2

How can I do this with QLIK?

Thanks in advance!

4 Replies
Chanty4u
MVP
MVP

If you just want to select second last date then

 

=max(VisitDate,2)

or

=Firststoredvalue(VisitDate,-2)

Dud-As
Contributor
Contributor
Author

Thank you for your quick response!

We have a VisitId for each of those records, would it be possible to know which VisitId is the one of the result =max(VisitDate,2)?

In order to identify the VisitId of the  second last date.

Thanks again!

tresesco
MVP
MVP

Use firstsortedvalue() and pass rank value 2 (third parameter) for second most recent date, like:

Firststoredvalue( VisitType, -VisitDate, 2)

Dud-As
Contributor
Contributor
Author

It works!

Thank you both!