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

load last qvd in folder

Hello all,

How do i load (Qlik script) all columns from the the latest modified ,qvd from a specific folder?

I saw multiple simmilar open topics on Community, but without correct anserws.

Regards,

Andrei

14 Replies
bramkn
Partner - Specialist
Partner - Specialist

FOR Each File in FileList('<path>')

AllQVDs:

    LOAD

             '$(File)' AS QVD,

             FileTime('$(File)') AS QVDModifiedDate

    AutoGenerate(1);

Next File

NewestQVD:

FIRST 1 LOAD

     QVD,

     QVDModifiedDate

RESIDENT AllQVDs

ORDER BY QVDModifiedDate DESC;

DROP TABLE AllQVDs;

This will result in a table with 1 record containing the newest QVD

Use Peek or Lookup to get the value of the QVD and load from this path.

hope this was clear enough

andreip21
Contributor III
Contributor III
Author

all clear until peek/ lookup function

bramkn
Partner - Specialist
Partner - Specialist

Peek(field_name[, row_no[, table_name ] ])


So something like this:

Let vLastQVD = Peek('QVD',0,'NewestQVD');

LOAD

*

FROM '$(vLastQVD)' (qvd);

shmulu
Contributor
Contributor

Can you help me in re-writing this for the last n files? Like if it were the last 5? This is what I have so far:

FOR Each File in FileList('FileLocation')

AllQVDs:
LOAD
'$(File)' AS QVD,
FileTime('$(File)') AS QVDModifiedDate
AutoGenerate(1);
Next File

NewestQVD:
FIRST 5 LOAD //determine the newest
QVD,
vFolder & '/' & QVD & '.qvd' as QVDFileName,
QVDModifiedDate
RESIDENT AllQVDs
ORDER BY QVDModifiedDate DESC;

DROP TABLE AllQVDs;


Set vFolder = 'FileLocation';
for each file in filelist(QVDFileName)
load * from [$(vFolder)/$(QVD)/.qvd] (qvd);
next File

BhaskarSharma
Contributor II
Contributor II

It is easy when there is a timestamp in the QVD name, or the names of the QVDs are different.

What if there's no timestamp in QVD name, and all QVDs are of same name... For example, in Google Drive, you can have multiple QVDs with same name... and if you wish to read the latest QVD, how do you do that?

 

Regards,

Bhaskar