Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
RubDev
Contributor
Contributor

Only load 10 most recent records per item

Hi, I have a data set with fields Site, Date and Result. I need script to load the nth most recent records based on Date for each Site. I was planning to load the whole dataset and then try to order by Site then Date and use Peek to assign a new ranking field but not sure if there is a cleverer way of doing it? Thanks for your help!!

1 Reply
JordyWegman
Partner - Master
Partner - Master

Hi,

I think your suggestion is already a good start. Check this example for having a flexible way of doing it:

let vLoadNthRecords = 2;

Table:
Load
	*
Where Counter <= $(vLoadNthRecords)	
;
Load
	Date,
	Application,
	If( Previous( Application ) <> Application, 
		1,
		IF( Previous( Application ) = Application,
			Peek( Counter , -1 ) + 1
			)
		)			as Counter
;
Load * Inline [
Date	,	Application
1-7-2021	,	A1
1-7-2021	,	A1
1-7-2021	,	A1
1-7-2021	,	A1
1-7-2021	,	A2
1-7-2021	,	A2
1-7-2021	,	A2
1-7-2021	,	A2
1-6-2021	,	A3
1-6-2021	,	A3
1-6-2021	,	A3
1-6-2021	,	A3
1-6-2021	,	A4
1-6-2021	,	A4
1-6-2021	,	A4
1-6-2021	,	A4
];

Jordy

Climber

Work smarter, not harder