Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
hic
Former Employee
Former Employee

There are a number of prefixes in QlikView, that help you load and transform data. One of them is the Crosstable transformation.

Whenever you have a crosstable of data, the Crosstable prefix can be used to transform the data and create the desired fields. A crosstable is basically a matrix where one of the fields is displayed vertically and another is displayed horizontally. In the input table below you have one column per month and one row per product.

 

Crosstable transformation4.png

 

But if you want to analyze this data, it is much easier to have all numbers in one field and all months in another, i.e. in a three-column table. It is not very practical to have one column per month, since you want to use Month as dimension and Sum(Sales) as measure.

 

Enter the Crosstable prefix.

 

It converts the data to a table with one column for Month and another for Sales. Another way to express it is to say that it takes field names and converts these to field values. If you compare it to the Generic prefix, you will find that they in principle are each other’s inverses.

 

The syntax is

 

   Crosstable (Month, Sales) Load Product, [Jan 2014], [Feb 2014], [Mar 2014], … From … ;

 

There are however a couple of things worth noting:

  • Usually the input data has only one column as qualifier field; as internal key (Product in the above example). But you can have several. If so, all qualifying fields must be listed before the attribute fields, and the third parameter to the Crosstable prefix must be used to define the number of qualifying fields.
  • It is not possible to have a preceding Load or a prefix in front of the Crosstable keyword. Auto-concatenate will however work.
  • The numeric interpretation will not work for the attribute fields. This means that if you have months as column headers, these will not be automatically interpreted. The work-around is to use the crosstable prefix to create a temporary table, and to run a second pass through it to make the interpretations:

 

   tmpData:

   Crosstable (MonthText, Sales)

   Load Product, [Jan 2014], [Feb 2014], … From Data;

 

   Final:

   Load Product,

      Date(Date#(MonthText,'MMM YYYY'),'MMM YYYY') as Month,

      Sales

      Resident tmpData;

   Drop Table tmpData;

 

Finally, if your source is a crosstable and you also want to display the data as a crosstable, it might be tempting to load the data as it is, without any transformation.

 

I strongly recommend that you don’t. A crosstable transformation simplifies everything and you can still display your data as a crosstable using a standard pivot table.

 

HIC

72 Comments
prodanov
Partner - Creator
Partner - Creator

No I don't. But I created small application for you, but I don't now how to upload it in this blog. For my applications, I use function that I build to automate this process.

Best regards

17,309 Views
Anonymous
Not applicable

Can you to send on my e-mail?

dfgui2000@hotmail.com

tks

0 Likes
17,309 Views
hic
Former Employee
Former Employee

The Crosstable transformation can be slow for large data amounts, an it is mainly due to the fact that it isn't multi-threaded.

HIC

0 Likes
17,309 Views
klaus_feldam
Creator II
Creator II

Brilliant, Henric.

Thanks for sharing.

0 Likes
17,309 Views
Sajid_Mahmood
Creator
Creator

Hi HIC,

I am also looking for the solution similar to Egnaldo's has requested above. I have table with Amount, Hours, Kilowatts which needs to be converted to crosstable.

Regards

Sajid

0 Likes
17,313 Views
hic
Former Employee
Former Employee
0 Likes
17,313 Views
Not applicable

hi Rob/Henric,

I  am still having an issue here.

The source file has new columns added(attribute columns).

I do a reload on the qlikview application and the data from the new columns does not appear.

Not sure if i am doing something wrong here.

I do use the following

test_data:

crosstable(build,power,2)

Load * from... .;

Currently, i am using the following version of the qlikview.

qlikview: 11.20.12235  SR5 X64 version.

thanks in advance.

Ramesh

0 Likes
17,313 Views
hic
Former Employee
Former Employee

It sounds as if you are doing the right thing, but it is impossible to say for certain without the data and the app.

HIC

0 Likes
17,313 Views
Anonymous
Not applicable

Hi,

Well explained.

Thanks for sharing.

0 Likes
17,313 Views
Not applicable

Hi Henric,

Thanks! Very helpful article.

T.P.S

0 Likes
17,313 Views