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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Get the File with the Max Date

Hello!

I have a folder named Selections with many CSV files that have the following format:

Dime_DD_MM_YYYY_HH_MM_SS.csv

For example:

Dime_01_04_2014_17_23_17.csv

Dime_02_04_2014_17_27_05.csv

Dime_03_04_2014_17_15_30.csv

Dime_03_04_2014_19_25_35.csv

What I need is to return the file that has the max date and then load the data into my model.

In this case, the file would be: Dime_03_04_2014_19_25_35.csv.

Do you know how could I do that?

Thank you!!!

4 Replies
its_anandrjs
Champion III
Champion III

Use filebasename() for this

Roop
Specialist
Specialist

I would perform:    

     For Each file in the directory and process the dates from the filenames    

     Then sort the table according to date    

     Set a variable as the first record in the table using Peek    

     Read the table from variable name

Hope this helps

bbi_mba_76
Partner - Specialist
Partner - Specialist

Hi,

see the attached file

its_anandrjs
Champion III
Champion III

Load your CSV file like the below code and every time the code runs it loads the latest file

Tab1:

LOAD

FileBaseName() as filename,

Timestamp(Timestamp#(Right(FileBaseName(),19),'DD_MM_YYYY_hh_mm_ss'),'DD/MM/YYYY hh:mm:ss') as Date

FROM

Dime_*.csv //Put * here to load all file in folder

(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

Maxdate:

LOAD

MaxString(filename) as Mdate

Resident Tab1;

LET vMaxFileName = peek('Mdate',-1,'Maxdate');

DROP Table Tab1;

New:

LOAD

*

FROM

Dime_*.csv

(txt, codepage is 1252, embedded labels, delimiter is '\t', msq)

Where filename = $(vMaxFileName);

Regards