Given this data set:
SummaryID Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15
25 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3
25 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3
25 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3
can the data be PIVOTed or CUBEd or whatever into this:
0 1 2 3 4 5 6 7
Q1 3
Q2 3
Q3 3
Q4 3
Q5 3
Q6 3
Q7 3
Q8 3
Q9 3
Q10 3
Q11 3
Q12 3
Q13 3
Q14 3
Q15 3
Essentially, the top table represents how feedback data is stored for a feedback system. Multiple reviewers are asked to rate a single reviewee on a scale from 0 to 7 for 15 questions. My example is a rather unlikely set of responses from 3 reviewers in order to show the pattern in the display table
The second table is how I want to display the data. Each “3” in the table represents the COUNT of responses for the given Q# and Rating combination. E.g., for Q5, 3 reviewees rated this person a “5”.
Clearly, the real data will be much more scattered about.
I’m hoping this is easy.
Thanks,
John Anderson
EDITED: here is my own first attempt:
SELECT * FROM (SELECT SummaryID, COUNT(Q1) AS Q1 FROM SummaryData WHERe SummaryID = 25
GROUP BY SummaryID) o
PIVOT (COUNT(Q1) FOR Q1 IN ([0], [1],[2],[3],[4],[5],[6],[7])) p
SummaryID 0 1 2 3 4 5 6 7
25 0 0 0 1 0 0 0 0
I’m getting a 1 under the 3, which is not right, and I can’t figure out how to extrapolate the code to include all the other Qs.
Thanks again,
John Anderson
EDITED: here is a sample dataset that I modeled in Excel to give results that will more closely resemble reality
SummaryID Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15
25 1 4 5 7 4 2 0 2 1 0 2 2 3 5 0
25 4 1 1 5 6 7 7 4 0 1 3 7 3 1 1
25 5 3 2 1 7 7 4 0 1 6 7 3 2 7 1
Results in:
0 1 2 3 4 5 6 7
Q1 1 1 1
Q2 1 1 1
Q3 1 1 1
Q4 1 1 1
Q5 1 1 1
Q6 1 2
Q7 1 1 1
Q8 1 1 1
Q9 1 2
Q10 1 1 1
Q11 1 1 1
Q12 1 1 1
Q13 1 2
Q14 1 1 1
Q15 1 2
You have to UNPIVOT first to get data into a format you need, and then PIVOT
Working sample: