Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

convert rows to columns based on ID and Type

Hi

I have the SQL out put in the below format. Need to convert them into the rows for each id, Based on the type the column name changes and store them in a QVD.

Id, First date , Last date, type

1, 01/Apr/2014, 04/Apr/2014, S

1,01/May/2014, 05/May/2014,B

1,10/May/2014,05/Jun/2014,C

2, 02/Apr/2014, 04/Apr/2014, S

2,03/May/2014, 05/May/2014,B

2,15/May/2014,05/Jun/2014,C

3, 01/Apr/2014, 04/Apr/2014, S

3,01/May/2014, 05/May/2014,B

3,10/May/2014,05/Jun/2014,C

....

   

IDS_first_dateS_last_dateB_first_dateB_last_dateC_first_dateC_last_date
11-Apr-144-Apr-141-May-145-May-1410-May-145-Jun-14
12-Apr-144-Apr-143-May-145-May-1415-May-145-Jun-14
31-Apr-144-Apr-141-May-145-May-1410-May-145-Jun-14

thanks..

JJ

10 Replies
sasiparupudi1
Master III
Master III

X:

Load * INLINE [

Id, First date , Last date, type

1,01/Apr/2014, 04/Apr/2014, S

1,01/May/2014, 05/May/2014,B

1,10/May/2014,05/Jun/2014,C

2,02/Apr/2014, 04/Apr/2014, S

2,03/May/2014, 05/May/2014,B

2,15/May/2014,05/Jun/2014,C

3,01/Apr/2014, 04/Apr/2014, S

3,01/May/2014, 05/May/2014,B

3,10/May/2014,05/Jun/2014,C];

Data:

LOAD

Id ,

Date(Sum(If(type='S',Date#([First date], 'DD/MMM/YYYY'))),'D-MMM-YYYY') AS S_first_date,

Date(Sum(If(type='S',Date#([Last date], 'DD/MMM/YYYY'))),'D-MMM-YYYY') AS S_last_date,

Date(Sum(If(type='B',Date#([First date], 'DD/MMM/YYYY'))),'D-MMM-YYYY') AS B_first_date,

Date(Sum(If(type='B',Date#([Last date], 'DD/MMM/YYYY'))),'D-MMM-YYYY') AS B_last_date,

Date(Sum(If(type='C',Date#([First date], 'DD/MMM/YYYY'))),'D-MMM-YYYY') AS C_first_date,

Date(Sum(If(type='C',Date#([Last date], 'DD/MMM/YYYY'))),'D-MMM-YYYY') AS C_last_date

Resident X

Group By Id ;

STORE Data into Data.qvd(qvd);

DROP TABLE X;

Untitled.jpg