Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
pratham39
Contributor III
Contributor III

Tranpose table - rows to column & column to rows

Hi , 

I have below table

pratham39_0-1677483848919.png

I want to convert this table into below format,

pratham39_1-1677483894936.png

Can somebody help?

Thanks

 

 

Labels (4)
1 Solution

Accepted Solutions
MayilVahanan

Hi

Try like below

CrossTable(Designation, Value)
Temp:
Load * Inline
[
City, L1, L2, L3, L4, L5
Bangalore, 1, 0, 0, 1, 1
Delhi, 1, 1, 1, 0, 0
Chennai, 0, 0, 0, 1, 1
];

GenericTemp:
Generic Load Designation, City, Value Resident Temp;

LevelJoin:
Load Distinct Designation Resident Temp;

FOR i = NoOfTables()-1 to 0 STEP -1;
LET vTable=TableName($(i));
IF WildMatch('$(vTable)','GenericTemp.*') THEN
LEFT JOIN ([LevelJoin]) LOAD * RESIDENT [$(vTable)];
DROP TABLE [$(vTable)];
ENDIF
NEXT i

 

Its similar to @neerajthakur , with merge all the generic table to single table. 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

10 Replies
BrunPierre
Partner - Master
Partner - Master

Hi , as below.

Data:
LOAD City as Designation,
Mumbia,
Banglore,
Delhi,
Pune

FROM SourceTable,
filters(
Transpose()
));

neerajthakur
Creator III
Creator III

You can use Crosstable function.

Refer this example: 

https://help.qlik.com/en-US/sense/May2022/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptPrefixes/...)

Thanks & Regards,
Please Accepts as Solution if it solves your query.
pratham39
Contributor III
Contributor III
Author

Hi 

thanks for input

Cross table wont work , please see my requirement clearly ,

with crosstable I won't get desire results which i m expecting 

Thanks

neerajthakur
Creator III
Creator III

tmpData:
Crosstable (Designation, Values)
Load * inline [
City, L1, L2, L3, L4, L5, L6
Mumbai, 1, 0, 0, 1, 1, 0
Bangalore, 0, 0, 1, 1, 1, 0
Delhi, 1, 1, 0, 0, 0, 0
Pune, 1, 0, 0, 1, 1, 1
];

Final:
Load Designation,
City as City2,
Values

Resident tmpData;

Drop Table tmpData;

Exit Script;

After crosstable you can use Pivot Table to show data like this.

xlitzdrama_0-1677583659425.png

 

Thanks & Regards,
Please Accepts as Solution if it solves your query.
anat
Master
Master

T:
CrossTable(city1,sales)
Load * Inline
[
city,L1,L2,L3
Mumbai,1,2,3
Delhi,2,3,4
Bgl,4,5,6

];

EXIT SCRIPT;

in front end use the pivot table to get desired results.

anat_0-1677585547951.png

 

pratham39
Contributor III
Contributor III
Author

Hi everyone ,

Thanks for your all inputs

I Don't want my expected output on frontend in pivot table,

Cant that be possible on backend only 

I want my expected table in backend only

Thanks

neerajthakur
Creator III
Creator III

tmpData:
Crosstable (Designation, Values)
Load * inline [
City, L1, L2, L3, L4, L5, L6
Mumbai, 1, 0, 0, 1, 1, 0
Bangalore, 0, 0, 1, 1, 1, 0
Delhi, 1, 1, 0, 0, 0, 0
Pune, 1, 0, 0, 1, 1, 1
];

Generic
Final:
Load
Designation,
City as City2,
Values

Resident tmpData;

Drop Table tmpData;

 

 

Exit Script;

 

xlitzdrama_0-1677606453199.png

 

Thanks & Regards,
Please Accepts as Solution if it solves your query.
MayilVahanan

Hi

Try like below

CrossTable(Designation, Value)
Temp:
Load * Inline
[
City, L1, L2, L3, L4, L5
Bangalore, 1, 0, 0, 1, 1
Delhi, 1, 1, 1, 0, 0
Chennai, 0, 0, 0, 1, 1
];

GenericTemp:
Generic Load Designation, City, Value Resident Temp;

LevelJoin:
Load Distinct Designation Resident Temp;

FOR i = NoOfTables()-1 to 0 STEP -1;
LET vTable=TableName($(i));
IF WildMatch('$(vTable)','GenericTemp.*') THEN
LEFT JOIN ([LevelJoin]) LOAD * RESIDENT [$(vTable)];
DROP TABLE [$(vTable)];
ENDIF
NEXT i

 

Its similar to @neerajthakur , with merge all the generic table to single table. 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
pratham39
Contributor III
Contributor III
Author

Thanks @MayilVahanan !!