This post describes a scenario for loading data into QlikView from multiple Excel files with similar but different names and a different number of tabs.
Let’s say you need to load multiple Excel files containing information about orders into your QlikView application. These files have different names, and each file may have a different amount of sheets.
For example, you may have several files with Order information from different sources for multiple dates such as:
CallCenter_Orders_20150312.xlsx InStore_Orders_20150311.xlsx SalesRep_Orders_20150312.xlsx SalesRep_Orders_20150311.xlsx
Let’s say each file has one or more sheets representing regions/divisions – West, Mid-West, North East, and South. Some files may have all 4 region/division sheets, while others may have just one region sheet.
This script is one possible way of loading this data in QlikView using a single script. With some adjustments, this script may also work for Qlik Sense, but I did not test exactly what changes would be needed.
//----------------------------------------------- // set the errormode so that your script will not fail when one or more of // the 4 sheets is not found in any particular file SET ErrorMode = 0;
OrdersFileData:
LOAD [CustomerID] as [Customer ID],
[OrderID as [Order Number],
[OrderDate] as [Order Date],
[ShipDate] as [Ship Date],
[Notes] as [Order Notes],
[Turn around days] as [Turnaround Days],
'WEST' as [Division] //identify region/division on all records
FROM [..DataText Files*Orders*.xlsx] //wildcard allows load from all
//xlsx files with “Orders” in the name
(ooxml, embedded labels, table is WEST); //load from the West sheet
CONCATENATE (OrdersFileData) //append data from Midwest sheet from all files LOAD [CustomerID] as [Customer ID], [OrderID] as [Order Number], [OrderDate] as [Order Date], [ShipDate] as [Ship Date], [Notes] as [Order Notes], [Turn around days] as [Turnaround Days], 'MIDWEST' as [Division] FROM [..DataText Files*Orders*.xlsx] (ooxml, embedded labels, table is MIDWEST);
CONCATENATE (OrdersFileData) //append data from Northeast sheet from all files LOAD [CustomerID] as [Customer ID], [OrderID] as [Order Number], [OrderDate] as [Order Date], [ShipDate] as [Ship Date], [Notes] as [Order Notes], [Turn around days] as [Turnaround Days], 'NORTHEAST' as [Division] FROM [..DataText Files*Orders*.xlsx] (ooxml, embedded labels, table is NORTHEAST);
CONCATENATE (OrdersFileData) //append data from South sheet from all files LOAD [CustomerID] as [Customer ID], [OrderID] as [Order Number], [OrderDate] as [Order Date], [ShipDate] as [Ship Date], [Notes] as [Order Notes], [Turn around days] as [Turnaround Days], 'SOUTH' as [Division] FROM [..DataText Files*Orders*.xlsx] (ooxml, embedded labels, table is SOUTH); STORE OrdersFileData into ..DataQVDsOrdersData.QVD; // if loading to QVD DROP Table OrdersFileData; //if loading to QVD and not needed in memory //-----------------------------------------------
