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.
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.
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:
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.
I find that there are often further manipulations you need to do after doing your crosstable load. A common one I have seen is where accountants put the year on it's own row above the Jan column (or in a merged cell) and then repeat that for each year. You then find when you load with * as Rob and Jason suggest you end up with fields Jan ... Dec, Jan2 ... Dec2, Jan3 ...
The resident load then needs to get a bit cleverer and do something like:
There is generally a way to deal with even the most untidy and inconsistent CROSSTABLE. I have had to in the past load the column headings into a table (using a TRANSPOSE laod) and then pick which of those headings make up the column list - building a string to use in the load script. All good fun!
When I download a date into Excel it can be converted (formatted) as a number (and then back to a date etc)
Crosstables convert dates to text
These can be converted in QlikView as DATE (NUM# (InvoiceDate)) as InvoiceDate ,
But when I download into excel its downloaded as text. And I have been unable to change this using whatever combination I have tried eg num (date# etc
I overcame this problem but using Value to convert the text to a value in Excel (this works). But what is the best way to format in QV to overcome this issue (not having to use value in Excel)
edit it works. Will at least OPDate2 does
date (num# (OPDate)) as OPDate , date (num#(OPDate)) as OPDate2,
Strange. I guess I just need to give the date a different name (as OPDate3 works too