Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
hobanwashburne
Creator
Creator

Dates and Crosstables

I have a db in the format:

Customer,

Product,

Year,

Month1,

Month2,

Month3...

I know that I will have to use the crosstable function, but when and how can I define the Months as Months so it can be used with an existing Master Calendar?

1 Solution

Accepted Solutions
JonnyPoole
Former Employee
Former Employee

The crosstable wizard in the 'table files' wizard is helpful for this structure:

1. Here i'm loading a source file with field hearders as you described

Capture1.PNG.png

2. When i select crosstable, increase the qualifiers to 3

Capture2.PNG.png

3. The pivotted new table is shown. note that months are showing under column 'Product' . We change that in fnal step

Capture3.PNG.png

4. Rename Product to Month. Here it is highlighted where i made the change in the script

Capture4.PNG.png

5. Here is the loaded result

Capture5.PNG.png

Now to hook this up to a master calendar, it would be good to create dates.  Back in the load script i can make a date between month and year through a resident load.

note: i changed the months from month1, month2 to actual month names

To add Calendar:

1. Name the first table ( I called it Temp) in the load script:

Temp:

CrossTable(Month, Data, 3)

LOAD Customer,

     Product,

     Year,

     Jan,

     Feb,

     Mar

FROM

(ooxml, embedded labels, table is Sheet1);

2.  Add the following resident load to build a date field using Year and Month:

Data:

load

  Customer,

  Product,

  date(date#( Year & '/' & Month, 'YYYY/MMM')) as Date,

  Data

Resident Temp;

3. Drop the first table 'Temp'

drop table Temp;

4. Now build a calendar table through a resident load loading the unique dates and calculating year, month,quarter and anything else you want off Date. That will ensure consistency.

Calendar:

load distinct

  Date,

  Year(Date) as Year,

  Month(Date) as Month,

  QuarterName(Date) as QuarterName

Resident Data;

Capture.PNG.png

View solution in original post

3 Replies
MarcoWedel

please post example data.

JonnyPoole
Former Employee
Former Employee

The crosstable wizard in the 'table files' wizard is helpful for this structure:

1. Here i'm loading a source file with field hearders as you described

Capture1.PNG.png

2. When i select crosstable, increase the qualifiers to 3

Capture2.PNG.png

3. The pivotted new table is shown. note that months are showing under column 'Product' . We change that in fnal step

Capture3.PNG.png

4. Rename Product to Month. Here it is highlighted where i made the change in the script

Capture4.PNG.png

5. Here is the loaded result

Capture5.PNG.png

Now to hook this up to a master calendar, it would be good to create dates.  Back in the load script i can make a date between month and year through a resident load.

note: i changed the months from month1, month2 to actual month names

To add Calendar:

1. Name the first table ( I called it Temp) in the load script:

Temp:

CrossTable(Month, Data, 3)

LOAD Customer,

     Product,

     Year,

     Jan,

     Feb,

     Mar

FROM

(ooxml, embedded labels, table is Sheet1);

2.  Add the following resident load to build a date field using Year and Month:

Data:

load

  Customer,

  Product,

  date(date#( Year & '/' & Month, 'YYYY/MMM')) as Date,

  Data

Resident Temp;

3. Drop the first table 'Temp'

drop table Temp;

4. Now build a calendar table through a resident load loading the unique dates and calculating year, month,quarter and anything else you want off Date. That will ensure consistency.

Calendar:

load distinct

  Date,

  Year(Date) as Year,

  Month(Date) as Month,

  QuarterName(Date) as QuarterName

Resident Data;

Capture.PNG.png