Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
ashish_2511
Creator
Creator

Fetch last two records from source

Dear Community

This is how my source data looks like -

   

Vin_NoInv_DateMileage_In
1233/17/201715000
1232/17/201712000
1231/17/201710000
2343/17/201715000
2342/17/201712000
2341/17/201710000

Issue - I want to fetch only the records pertaining to the latest two Inv_dates wrt to the vin_no, sorted by Inv_Date.

****E.g; In my qvw I only want the  records highlighted in Red****

Your ideas will be greatly appreciated.

Thanks!

Sneh

1 Solution

Accepted Solutions
sunny_talwar

May be try this

Table:

LOAD * INLINE [

    Vin_No, Inv_Date, Mileage_In

    123, 3/17/2017, 15000

    123, 2/17/2017, 12000

    123, 1/17/2017, 10000

    234, 3/17/2017, 15000

    234, 2/17/2017, 12000

    234, 1/17/2017, 10000

];

FinalTable:

NoConcatenate

LOAD *

Resident Table

Where Vin_No <> Previous(Previous(Vin_No))

Order By Vin_No, Inv_Date desc;

DROP Table Table;

View solution in original post

2 Replies
PrashantSangle

Hi,

use firstsortedValue(field,-date)

for more details see example in help menu

Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
sunny_talwar

May be try this

Table:

LOAD * INLINE [

    Vin_No, Inv_Date, Mileage_In

    123, 3/17/2017, 15000

    123, 2/17/2017, 12000

    123, 1/17/2017, 10000

    234, 3/17/2017, 15000

    234, 2/17/2017, 12000

    234, 1/17/2017, 10000

];

FinalTable:

NoConcatenate

LOAD *

Resident Table

Where Vin_No <> Previous(Previous(Vin_No))

Order By Vin_No, Inv_Date desc;

DROP Table Table;