Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
 
					
				
		
Hi all,
I am working on a .qvw that read the fist line and last line of qlikview log files. I want to know how long does the specific job run.
How should I write the script in order to get the first row and last row date time?
Thanks..
I have written something for reference...
//search all log location in C:/QlikView/log
sub
 DoDir (Root)
for each Ext in 'txt'
for each File in filelist (Root&'\TaskLog.' &Ext)
Info:
Load '$(File)' as Name, FileSize( '$(File)' ) as
Size, FileTime( '$(File)' ) as FileTime
autogenerate 1;
next File
next Ext
for each Dir in dirlist (Root&'\*' )
call DoDir (Dir)
next Dir
end sub
call DoDir ('C:\Qlikview\log')
//for each location, read the TaskLog.txt file and save it in a table.
for a=0 to noofrows('Info') -1;
 let location=peek('Name',a,'Info');
StartFile:
LOAD 
 $(a) as FileNo,
 replace(Replace('$(location)',left('$(location)',58),''),'\TaskLog.txt','') as FileName,
 left(@1,18) as Date
FROM
$(location)
(txt, utf8, no labels, delimiter is '\t', msq);
next 
 
					
				
		
 whiteline
		
			whiteline
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		First, transform your date format from string to numeric date (so that you can sort):
timestamp#(left(@1,18), 'DD-MM-YYYY hh:mm:ss') as Date
'DD-MM-YYYYhh:mm:ss' here is an example, you should use suitable format.
Now you can use FirstSortedValue to sort and aggregate your table:
FirstStrings:
LOAD
FileName,
FirstSortedValue(Date, Date) as FirstString
Resident StartFile
Group by FileName;
LastStrings:
LOAD
FileName,
FirstSortedValue(Date, -Date) as LastString
Resident StartFile
Group by FileName;
I didn't find any data string in your example, except Date field.You should replace it (bold) with desired.
 
					
				
		
 whiteline
		
			whiteline
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		First, transform your date format from string to numeric date (so that you can sort):
timestamp#(left(@1,18), 'DD-MM-YYYY hh:mm:ss') as Date
'DD-MM-YYYYhh:mm:ss' here is an example, you should use suitable format.
Now you can use FirstSortedValue to sort and aggregate your table:
FirstStrings:
LOAD
FileName,
FirstSortedValue(Date, Date) as FirstString
Resident StartFile
Group by FileName;
LastStrings:
LOAD
FileName,
FirstSortedValue(Date, -Date) as LastString
Resident StartFile
Group by FileName;
I didn't find any data string in your example, except Date field.You should replace it (bold) with desired.
 
					
				
		
Thanks.
I use First Value instead of FirstSortedValue and now can get the correct answer.
