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: 
Not applicable

latest row per id

Hello all,

Hope everyone is having a good day.

I would like to fetch latest row per id. One id has multiple support contracts associated with them. From these multiple rows I would like to get that row which has highest start date.

Please let me know how can I achieve that.

Any help is appreciated.

Best

Parth

1 Solution

Accepted Solutions
sunny_talwar

Then try like this:

Table:

LOAD id,

           [start date],

           ....

FROM ....;

Left Join (Table)

LOAD id,

           Max([start date]) as [start date],

           1 as Flag

Resident Table

Group By id;

This will put 1 for max start date. In case you need 0 for other dates, you will have to do a resident load

FinalTable:

LOAD id,

           [start date],

           ....,

           If(Flag = 1, 1, 0) as Flag

Resident Table;

DROP Table Table;

View solution in original post

6 Replies
sunny_talwar

How does your raw data looks like? can you share few rows of data?

Something along these lines to should work:

Table:

LOAD id,

           [start date],

           ....

FROM ....;

Right Join (Table)

LOAD id,

           Max([start date]) as [start date],

Resident Table

Group By id;

Anil_Babu_Samineni

Front end solution may be this

If(Id = Aggr(Max(Rowno(TOTAL)),[start date]), id)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Not applicable
Author

Hi Sunny,

Ideally I would like to create a new column called flag which identifies which row is the latest. Please see below how the data looks like:

    

supp_ididtypestart dateend dateflag
11gold12/1/199011/30/19950
21gold12/1/199511/30/19990
31silver12/1/199911/30/20191
42silver8/15/20158/14/20160
52gold8/15/20168/14/20171
63gold9/1/20158/31/20171
74silver12/1/201611/30/20181
85silver1/1/201512/31/20160
95gold1/1/201612/31/20171

Please let me know if this is doable.

Thank you

Parth

sunny_talwar

Then try like this:

Table:

LOAD id,

           [start date],

           ....

FROM ....;

Left Join (Table)

LOAD id,

           Max([start date]) as [start date],

           1 as Flag

Resident Table

Group By id;

This will put 1 for max start date. In case you need 0 for other dates, you will have to do a resident load

FinalTable:

LOAD id,

           [start date],

           ....,

           If(Flag = 1, 1, 0) as Flag

Resident Table;

DROP Table Table;

Not applicable
Author

Thank you Sunny!!

Not applicable
Author

Thank you Anil!!