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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Luqlik
Contributor
Contributor

Find Maximum of a subset

Hello everyone,

I bet you can help me with this one! 

In my app, I access the following table from a database:

BookingID  Booking Date
1 29.01.2020
1 02.02.2015
1 05.01.2021
2 01.01.1993
2 03.02.2020
3 01.02.2021
3 04.02.2020
3 07.03.2020
3 02.01.2020

 

I now want to add a new column that indicates which booking record for a Booking ID has the latest BookingDate.

Example:

BookingID 1 exists 3 times. The highest BookingDate for BookingID 1 is in row 3. This is to be indexed in a newly added column.

Like this

BookingID  Booking Date Latest Booking Date of BookingID? 
1 29.01.2020 no 
1 02.02.2015 no 
1 05.01.2021 yes
2 01.01.1993 no 
2 03.02.2020 yes
3 01.02.2021 yes
3 04.02.2020 no 
3 07.03.2020 no 
3 02.01.2020 no 

 

How can I implement this as uncomplicated as possible?

Please excuse my beginner question, but I am not that experienced yet.

Many thanks in advance.

Luqlik

 


Translated with www.DeepL.com/Translator (free version)

Labels (1)
1 Reply
rubenmarin

Hi, an easy way could be adding a field in scripts, just load the data from the most recent by booking id and the first of each BookingId will be the last, like:

tmpBaseData:
LOAD
  BookingID,
  [Booking Date]
from ...;

FinalData:
LOAD
  BookingID,
  [Booking Date]
  If(BookingID=Peek(BookingID),'no,'yes') as isLatestookingID
Resident tmpBaseData
Order By BookingID, [Booking Date] desc;

DROP Table tmpBaseData;