Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Table transformation

Hi,

I figured out how to do simple transformations and rotations in QlikView but now I came across an excel "table" with both vertical and horizontal headers.

CountryAB
XFrance1020
Ireland3040
YFrance5060
Ireland7080

I need to transform the table in something useful that matches my data model: (never mind the sorting)

DCountryXY
AFrance1050
BFrance2060
AIreland3070
BIreland4080

So the two last column headers A,B need to become values in a new column D. And the vertical headers need to become column headers.

I'm not even sure if QlikView can handle such a transformation.

Any input would be appreciated.

Alyson

5 Replies
awhitfield
Partner - Champion
Partner - Champion

Hi Alyson,

you would do this use a Cross Table load, check out the Qlikview Reference Manual, there's an example similar to yours

Andy

buzzy996
Master II
Master II

i think pivot/cross table is the soltuon,

load ur data as it's

select chart type as pivot table and try to move ur objects rows as columns ans reversal.

sunny_talwar

Try this:

Table:

CrossTable(D, Data, 2)

LOAD F1,

    Country,

    A,

    B

FROM

[https://community.qlik.com/thread/159077]

(html, codepage is 1252, embedded labels, table is @1);

Table2:

Generic LOAD D,

  Country,

  F1,

  Data

Resident Table;

DROP Table Table;


Also attaching the application (PFA)

Best,

Sunny

chriscammers
Partner - Specialist
Partner - Specialist

I'm not sure why you would want to do this but here is a sample that uses crosstable to turn the "A" and "B" columns into dimension rows and then iterates over the original attribute containing "X" and "Y" to repivot by the original dimensions.

Produce the crosstable load

//The following statement will produce 1 row for each "data column"

//the attribute columns are defined by the third parameter of the

//crosstable statement in this case there are two attributes.

OriginalData:

CrossTable('NewAttribute','DataValue',2)

Load * Inline [

Attribute1,Country,A,B

X,France,10,20

X,Ireland,30,40

Y,France,50,60

Y,Ireland,70,80

];

Iterate over the field

Let vAttrCount = FieldValueCount('Attribute1');

For i=1 to vAttrCount

  Let vAttr = FieldValue('Attribute1',$(i));

  //Test to see if the table exists if no then create it else perform a join(Full Outer)

  If isnull(TableNumber('Final')) then

  Final:

  Load

  Country,

  NewAttribute,

  DataValue as [$(vAttr)]

  Resident OriginalData

  Where Attribute1 = '$(vAttr)';

  Else

  Join(Final)

  Load

  Country,

  NewAttribute,

  DataValue as [$(vAttr)]

  Resident OriginalData

  Where Attribute1 = '$(vAttr)';

  ENDIF

Next

//dropping original table to avoid invalid associations

Drop table OriginalData;

Not applicable
Author

Hi,

Just try by dragging and dropping the first column of your pivot table  to the other orientation and the place where you required.

Priyantha.