Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I have following requirement. I got stuck in one point. Can someone help me out for that?
1. All the csv in the folder starts with PRISM(EMPLOYEE_CMO_2012_09,EMPLOYEE_Markets_2013_02,EMPLOYEE_City_2013_09...).For your information all the file ends with YYYY_MM.
2. As discussed there is a change in the field name from 2013_08. So whatever the file which has been received from 2013_08 will have different new name. All the files which was removed before 2013_08 will have old field name.
3. So while loading data from the new file (> 2013_07) it should load with the new fields and while loading from the data from the file (<= 2013_07) it should load with the old field name only.
----------------------------
This is the code which I have written to scan the files from a folder. But got stuck while loading csv files based the condition.
For each vFile in FileList('C:\QlikView\Source\EMPLOYEE_*.csv')
Files: // reading csv files with yearmonth in filename
LOAD *,
right(subfield(FileName, '.' ,1),7) as YearMonth
LOAD '$(vFile)' as FilePath,
subfield('$(vFile)','\',-1) as FileName
autogenerate 1;
if(File name contains >= 2013_08 it should load with new fields) // What should be the condition here???
TableName:
EmpName as CustName,
EmpId as CustId,
field1,
field2
from
C:\QlikView\Source\EMPLOYEE_*.csv //How should I pass the filename here???
else
CustName as CustName,
CustId as CustId,
field1,
field2
from
C:\QlikView\Source\EMPLOYEE_*.csv //How should I pass the filename here???
end if
NEXT vFile
LET TwoMonths = date(AddMonths(Today(),-2),'YYYY_MM');
//if '$(vFileName)' follows '$(TwoMonths)' then
You should mark this question as answered...
Thank you. I will check and update you.
By the way when we are in the starting of the year(Jan-2014), will it load Jan-2014 data and Dec-2013 data? Please answer...
As I don't have the access I couldn't verify that.
By the way any idea how can I load latest 2 weeks of data? (i,e Current week and Previous week). Actually I was looking for that also. Also make sure that when we are in the first week of the year it should load first the current year and last week of the previous year as well. Any idea on this? Please help...
In Jan/2014 this variable
LET TwoMonths = date(AddMonths(Today(),-2),'YYYY_MM');
will contain 2013_11 so "follow" operador will work fine
= date(WeekStart(Today())-7,'YYYYMMDD') will return the 1st day of last week, so you can compare
Hi,
I am not sure but can you try something like,
For Each '$(vFileName)' follows all files in your folder(FileName_*).
If vFileName = max(Value in the folder) (eg. if max value is 2013_07) then
Put here your loading script.
else if vFileName = max(Value in the folder)- 1 then
Put here your loading script.
endif
Next
This script will give you only two files because of your if condition in for loop.
Please update if it works, else just share any sample example so that you will get proper o/p.
Regards,
Yojas