Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
marcel_olmo
Partner Ambassador
Partner Ambassador

Problems "crosstabling" a table

Hi guys, here's my problem.

I have a table like this :

1.png

And this is my desired result :

2.png

I'm trying to solve it with crosstable function, but it's not working, I don't know why.

Anybody knows how to do that??

Many thanks in advance!!!!

1 Solution

Accepted Solutions
Sokkorn
Master
Master

Hi Marcel,

Try this script

[DS]:

LOAD * INLINE [

Field1, Attribute, Value

A, xx, 1

A, yy, 2

A, zz, 3

A, xx, 4

A, yy, 5

];

[TMP1]:

GENERIC LOAD * RESIDENT [DS];

[RESULT]:

LOAD DISTINCT Field1 RESIDENT [DS];

DROP TABLE [DS];

FOR i = 0 to NoOfTables()

TableList:

LOAD TableName($(i)) AS Tablename AUTOGENERATE 1

WHERE WildMatch(TableName($(i)), 'TMP1.*');

NEXT i

FOR i = 1 to FieldValueCount('Tablename')

LET vTable = FieldValue('Tablename', $(i));

LEFT JOIN ([RESULT]) LOAD * RESIDENT $(vTable);

DROP TABLE $(vTable);

NEXT i

drop table TableList;

HTH and let me know.

Regards,

Sokkorn

View solution in original post

4 Replies
martinpohl
Partner - Master
Partner - Master

Something like that?

Unbenannt.JPG

Go to Properties/Presentation and mark Horizontal

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

Hi Martin, this is not as easy as you think.

I mean the first picture is a table, and the second one is my Desired Table. I want all the rows converted into columns. And it's supposed to be the result of the crosstable function.

Do yo know how to do it?

Sokkorn
Master
Master

Hi Marcel,

Try this script

[DS]:

LOAD * INLINE [

Field1, Attribute, Value

A, xx, 1

A, yy, 2

A, zz, 3

A, xx, 4

A, yy, 5

];

[TMP1]:

GENERIC LOAD * RESIDENT [DS];

[RESULT]:

LOAD DISTINCT Field1 RESIDENT [DS];

DROP TABLE [DS];

FOR i = 0 to NoOfTables()

TableList:

LOAD TableName($(i)) AS Tablename AUTOGENERATE 1

WHERE WildMatch(TableName($(i)), 'TMP1.*');

NEXT i

FOR i = 1 to FieldValueCount('Tablename')

LET vTable = FieldValue('Tablename', $(i));

LEFT JOIN ([RESULT]) LOAD * RESIDENT $(vTable);

DROP TABLE $(vTable);

NEXT i

drop table TableList;

HTH and let me know.

Regards,

Sokkorn

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

Hi Cheav, this is what I was looking for!!

I didn't know it was gonna be so hard. Now it works like a charm.

Many thanks!!

Regards, Marcel.