-1

I have a survey data where the questions are column names are [Question1], [Question2], [Question3] and response is the row value.

The ResponseID is unique and has one row per table.I wanted to unpivot the data where I have more than one response ID and the questions and responses are recorded in separate columns.I tried the below query but the Question name is not appearing in the dataset. Appreciate the support.Thank you

         SELECT [Response Id],[Date Created], Question
     FROM(
                  SELECT [Response Id], [Date Created],[Question1], 
                            [Question2],  [Question3]
           FROM dbo.surveys) AS cp UNPIVOT (Question FOR Questions IN (,[Question1],[Question2],[Question3]
            ) AS up;

Can this be handled directly in tableau?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
user1046415
  • 779
  • 4
  • 23
  • 43
  • Their is a pivot option, Can you show the screenshot? – Siva Apr 05 '18 at 17:08
  • I am using 10.5, I highlighted the fields but there is no pivot option – user1046415 Apr 06 '18 at 14:10
  • Pivot is supported only for excel data source in tableau which is weird . – user1046415 Apr 06 '18 at 14:25
  • Pivot is supported for several data sources, not just excel. Are you using custom SQL? That's usually not the best approach. – Alex Blakemore Apr 06 '18 at 20:32
  • 1
    If you are going to rewrite the question to be completely different, it's best to close this question and open a new one rather than rewriting the whole question. That way our answers and comments don't seem out of place. – Sam M Apr 07 '18 at 00:35
  • 1
    Do not replace existing questions with a different one. That’s considered vandalism. Post a new question, and wait the normal amount of time before putting a bounty on that new post. – Martijn Pieters Apr 07 '18 at 19:43
  • I'm voting to close this question as off-topic because the answers seems invalid – user1046415 Apr 08 '18 at 06:16

1 Answers1

1

Yes it is possible, although I'm not 100% certain which of the two methods you will need to use for Sql Server as the data source. Try this first method and if that doesn't work, check further below for a second way. From the Tableau Help at https://onlinehelp.tableau.com/current/pro/desktop/en-us/pivot.html:

  1. On the data source page, in the grid, select two or more fields to pivot.
  2. Click the drop-down arrow next to the field name, and then select Pivot.

The original fields in the data source are replaced with new fields called “Pivot field names” and “Pivot field values.” You can always rename the new pivot fields. If you decide that using pivot does not help, you can undo the changes or remove the pivot. Alternatively, you can change the data type of the pivot field to adjust how the data is interpreted.

If that does not work, the help document contains instructions for using custom sql to accomplish the task.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Sam M
  • 4,136
  • 4
  • 29
  • 42