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

Convert columns into rows

Hi 

I have a long data file with months name as columns and want to reshape the table in load script. tried crosstable but there was no success

here is example data what i have

SerialMin_2020_01Min_2020_02Min_2020_03Mean_2020_01Mean_2020_02Mean_2020_03Max_2020_01Max_2020_02Max_2020_03
123451111.51.51.5333

 

and i want to convert this to this

SerialDateMinMeanMax
123452020-Jan11.53
123452020-Feb11.53
123452020-Mar11.53

 

How do i do that. 

Labels (2)
2 Solutions

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

How about:

TempData:
CrossTable(Stat_Month, Value)
LOAD *
FROM
[https://community.qlik.com/t5/New-to-Qlik-Sense/Convert-columns-into-rows/td-p/1760422]
(html, utf8, UserAgent is 'Mozilla/5.0', embedded labels, table is @1);

MasterData:
LOAD
  Serial & '-' & Date as Key,
  *
;
LOAD
  Serial,
  Date(MakeDate(SubField(Stat_Month,'_',2), SubField(Stat_Month,'_',3)), 'YYYY-MMM') as Date,
  SubField(Stat_Month,'_',1) as Stat,
  Value
Resident TempData
;
Drop Table TempData;

Stats:
Generic LOAD
  Key,
  Stat,
  Value
Resident MasterData
;
DROP Fields Value, Stat;

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

View solution in original post

Shani1
Contributor II
Contributor II
Author

Exactly what i was looking for. many thanks to both of you 

View solution in original post

5 Replies
Anil_Babu_Samineni

One way perhaps this way?

 

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

How about:

TempData:
CrossTable(Stat_Month, Value)
LOAD *
FROM
[https://community.qlik.com/t5/New-to-Qlik-Sense/Convert-columns-into-rows/td-p/1760422]
(html, utf8, UserAgent is 'Mozilla/5.0', embedded labels, table is @1);

MasterData:
LOAD
  Serial & '-' & Date as Key,
  *
;
LOAD
  Serial,
  Date(MakeDate(SubField(Stat_Month,'_',2), SubField(Stat_Month,'_',3)), 'YYYY-MMM') as Date,
  SubField(Stat_Month,'_',1) as Stat,
  Value
Resident TempData
;
Drop Table TempData;

Stats:
Generic LOAD
  Key,
  Stat,
  Value
Resident MasterData
;
DROP Fields Value, Stat;

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

Shani1
Contributor II
Contributor II
Author

Many Thanks, This is working as it supposed to be. 

It create 4 tables, is it possible to make a single table 

MayilVahanan

HI @Shani1 

You can use HIC solution for this 
https://community.qlik.com/t5/Qlik-Design-Blog/The-Generic-Load/ba-p/1473470

In addition to Rob solution, just added HIC solution for your reference. 
Ex:

TempData:
CrossTable(Stat_Month, Value)
LOAD *
FROM
[https://community.qlik.com/t5/New-to-Qlik-Sense/Convert-columns-into-rows/td-p/1760422]
(html, codepage is 1252, embedded labels, table is @1);


MasterData:
LOAD
Serial & '-' & Date as Key,
*
;
LOAD
Serial,
Date(MakeDate(SubField(Stat_Month,'_',2), SubField(Stat_Month,'_',3)), 'YYYY-MMM') as Date,
SubField(Stat_Month,'_',1) as Stat,
Value
Resident TempData
;
Drop Table TempData;

Stats:
Generic LOAD
Key,
Stat,
Value
Resident MasterData
;
DROP Fields Value, Stat;
Let vNoOfTables = NoOfTables();

For cnt=0 to $(vNoOfTables)-1

Let vTableName=TableName($(cnt));

TableList:

LOAD

'$(vTableName)' as TableName

Autogenerate(1);

Next

Let vFirstTableName=Peek('TableName',0,'TableList');

Let vNumberOfRows = NoOfRows('TableList')-1;

For cnt=1 to $(vNumberOfRows)

Let vTableName=Peek('TableName',$(cnt),'TableList');

Join($(vFirstTableName))

LOAD Distinct * Resident $(vTableName);

DROP Table $(vTableName);

Next

Rename Table $(vFirstTableName) to MainTable;

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

Exactly what i was looking for. many thanks to both of you