Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Un-Pivoting Table in Crystal Reports Post Reply Post New Topic
Author Message
Capson
Newbie
Newbie
Avatar

Joined: 23 Jan 2013
Location: United States
Online Status: Offline
Posts: 20
Quote Capson Replybullet Topic: Un-Pivoting Table in Crystal Reports
     Posted: 23 Jan 2013 at 4:25am
Hello, first I am very new to CR.

I’m working with Lime Survey and ultimately want to use Crystal Reports for my final output, and am looking for help with the intervening steps. I have one row per response record, with 100+ questions, which are split into several sections. The output looks like a cross-tab with a column per question, but I think the data needs to be unpivoted before I can work with it in Crystal Reports.
To illustrate – in Excel the output from Lime Survey looks like this:


ID      Subject     Relationship     1Section     1SQuestion1     1SQuestion2     2Section     2SQuestion1     2SQuestion2
1     John     Boss             1Section     2             4             2Section     3             4
2     John     Peer             1Section     4             3             2Section     2             5
3     Sally     Boss             1Section     3             3             2Section     4             5
4     Sally     Peer             1Section     5             6             2Section     1             3


Here’s what I ultimately need it to look like:

ID     Subject     Relationship   1Section        Col5           Col6
1     John     Boss            1Section        1SQuestion1     2
1     John     Boss            1Section        1SQuestion2     4
2     John     Peer            1Section        1SQuestion1     4
2     John     Peer            1Section        1SQuestion2     3
3     Sally     Boss            1Section        1SQuestion1     3
3     Sally     Boss            1Section        1SQuestion2     3
4     Sally     Peer            1Section        1SQuestion1     5
4     Sally     Peer            1Section        1SQuestion2     6
1     John     Boss            2Section        2SQuestion1     3
1     John     Boss            2Section        2SQuestion2     4
2     John     Peer            2Section        2SQuestion1     2
2     John     Peer            2Section        2SQuestion2     5
3     Sally     Boss            2Section        2SQuestion1     4
3     Sally     Boss            2Section        2SQuestion2     5
4     Sally     Peer            2Section        2SQuestion1     1
4     Sally     Peer            2Section        2SQuestion2     3

I think I need to un-pivot it by Sections:

ID     Subject     Relationship     1Section     1SQuestion1     1SQuestion2
1     John     Boss             1Section     2             4
2     John     Peer             1Section     4             3
3     Sally     Boss             1Section     3             3
4     Sally     Peer             1Section     5             6

then
ID     Subject     Relationship     2Section     2SQuestion1     2SQuestion2
1     John     Boss             2Section     3             4
2     John     Peer             2Section     2             5
3     Sally     Boss             2Section     4             5
4     Sally     Peer             2Section     1             3


Then stack the two sections. Is that right & if so, how should I do that? Or is there a better way?

Depending on the survey, there might be 4 sections or there could be as many as 15. So, is there a way to do this dynamically, based on the number of sections?

Thanks
IP IP Logged
Capson
Newbie
Newbie
Avatar

Joined: 23 Jan 2013
Location: United States
Online Status: Offline
Posts: 20
Quote Capson Replybullet Posted: 23 Jan 2013 at 4:27am
I guess the formatting did not work!
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum