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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikviewforum
Creator II
Creator II

Loading the two fields as same field from csv.

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

16 Replies
Clever_Anjos
Employee
Employee

LET TwoMonths = date(AddMonths(Today(),-2),'YYYY_MM');

//if '$(vFileName)' follows '$(TwoMonths)' then

Clever_Anjos
Employee
Employee

You should mark this question as answered...

qlikviewforum
Creator II
Creator II
Author

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.

qlikviewforum
Creator II
Creator II
Author

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...

Clever_Anjos
Employee
Employee

In Jan/2014 this variable

LET TwoMonths = date(AddMonths(Today(),-2),'YYYY_MM');

will contain 2013_11 so "follow" operador will work fine


Clever_Anjos
Employee
Employee

= date(WeekStart(Today())-7,'YYYYMMDD') will return the 1st day of last week, so you can compare

Not applicable

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