While analyzing data, we come across situations where we desire columns to become rows and vice-versa. It is not just about transposing, it also involves rolling up many columns together or repeating many values in a row many times to achieve the desired column and row layout in the table.
Input data
Consider the following input data, which shows region-wise sales of a certain product for each quarter. We create a delimited file (CSV) with the below given data.
Quarter,Region1,Region2,Region 3
Q1,124,421,471
Q2,415,214,584
Q3,417,321,582
Q4,751,256,95
Loading Input Data
We load the above input data using the script editor, which is invoked by pressing Control+E. Choose the option Table Files and browse for the Input file. After choosing the options as shown below, click Next.
Crosstable Options
In the next window (File Wizard ā Options), click on theĀ CrosstableĀ button. It highlights the columns in different colors. The pink color shows theĀ qualifier field, which is going to be repeated across many rows for each value of theĀ Attribute Field. The cell values under the Attribute fields are taken as the data. Click OK.
Crosstable Transformation
The transformed data appears in which all the Region fields are clubbed to one column but with values repeating for each quarter.
Load Script
The Load script for the crosstable transformations shows the commands given below.
Crosstable Data
On creating a Table Box sheet object using the menu Layout ā New Sheet Objects ā Table Box, we get the following output.