Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Crosstable - multiple excel sheets issue

Hi all,

I have an excel file with several sheets (one per month) updated monthly with the last six months of sales values and one column with units for the last month.

 

EXAMPLE:

              

DescriptionCodeAugSepOctNovDicJanTotalUnits
product a3915241544184
product B3915313311251616922
product C39164653224224
product d391657273552923
prouct e39166474716
product f391671449711311212297685178

From each sheet I have to upload the value of the last month (sales) and the value in the UNITS column.

How can I upload the sales values in all sheets as a crosstable? How can I identify the Units column as part of the current month? in this example, the units are from Jan.

Next month I'll have a similar file with columns from Sept to Feb. and Units values for Feb

Thanks.

1 Solution

Accepted Solutions
adamdavi3s
Master
Master

This worked for me with your data, with the exception that you need to make sure the column headings are consisten e.g. units and Units

ODBC CONNECT32 TO [Excel Files;DBQ=E:\data_YTD.xlsx];

tables:

SQLtables;

months:

load *, month(makedate(Year,Month,'01')) as loadmonth,makedate(Year,Month,'01') as loaddate;

load TABLE_NAME, mid(TABLE_NAME,2,4) as Year, num(mid(TABLE_NAME,7,2)) as Month

resident tables;

drop table tables;

FOR i = 0 to NoOfRows('months')-1

  LET sheetName = purgechar(purgeChar(peek('TABLE_NAME', i, 'months'), chr(39)),chr(36));

  LET columnName = purgeChar(peek('loadmonth', i, 'months'), chr(39));

  LET loadDate = purgeChar(peek('loaddate', i, 'months'), chr(39));

  Sales:

  LOAD Desc,Code,Units, $(columnName) as data, '$(loadDate)' as date

  FROM (ooxml, embedded labels, table is [$(sheetName)])

  WHERE len(Desc)>0;

NEXT;

drop table months;

View solution in original post

4 Replies
adamdavi3s
Master
Master

This worked for me with your data, with the exception that you need to make sure the column headings are consisten e.g. units and Units

ODBC CONNECT32 TO [Excel Files;DBQ=E:\data_YTD.xlsx];

tables:

SQLtables;

months:

load *, month(makedate(Year,Month,'01')) as loadmonth,makedate(Year,Month,'01') as loaddate;

load TABLE_NAME, mid(TABLE_NAME,2,4) as Year, num(mid(TABLE_NAME,7,2)) as Month

resident tables;

drop table tables;

FOR i = 0 to NoOfRows('months')-1

  LET sheetName = purgechar(purgeChar(peek('TABLE_NAME', i, 'months'), chr(39)),chr(36));

  LET columnName = purgeChar(peek('loadmonth', i, 'months'), chr(39));

  LET loadDate = purgeChar(peek('loaddate', i, 'months'), chr(39));

  Sales:

  LOAD Desc,Code,Units, $(columnName) as data, '$(loadDate)' as date

  FROM (ooxml, embedded labels, table is [$(sheetName)])

  WHERE len(Desc)>0;

NEXT;

drop table months;

Not applicable
Author

Hi Adam, 

Thank you very much for your reply.

Let me see if I understand correctly.  This is creating the months and dates from the names of the excel sheets in the file, extracting them them from the TABLE_NAME table?

One question, I am getting an error:

Field not found - <jul>

Sales: 

  LOAD Desc,Code,Units, jul as data, '01/07/2016' as date 

  FROM (ooxml, embedded labels, table is [2016-07]) 

  WHERE len(Desc)>0

This is for every month.

Do the Months in the file have to match the MonthNames variable?

SET MonthNames='ene;feb;mar;abr;may;jun;jul;ago;sep;oct;nov;dic'?

Thanks

Not applicable
Author

Hi Adam,

The error was due to difference in the file  vs. the MonthNames

I changed them and it worked perfectly.

Thank you very much for your assistance,

Regards.

Ramon

adamdavi3s
Master
Master

Hi Ramon,

Excellent news, I am glad it works for you, it was a fun puzzle.

Kind regards


Adam