Survey responses
Survey answers stored one row per respondent and question. Pivot them into one row per respondent, with a gap where someone skipped a question.
intermediate · Skills: Pivot column, Dynamic pivot values, Averages per question · Updated 2026-11-04
Data files
- responses.csv — RespondentID, Question, Score (1–5). One respondent skipped Q3.Download CSV (521 B)
Queries
Validated in the Power Query Exercises simulator against the files above. Paste them into Excel or Power BI yourself; the header comments explain each source binding.
One row per respondent responses-wide.pq
Download .pqQuestions become columns; skipped answers stay null. Returns 7 rows: RespondentID, Q1 Ease, Q2 Speed, Q3 Support, Q4 Recommend.
// One row per respondent
// Pack: Survey responses (Power Query Exercises, https://powerqueryexercises.com/downloads/survey-responses-pivot)
//
// Source bindings
// In the Power Query Exercises simulator each name below is bound directly to a pack file. In Excel or
// Power BI Desktop the first steps of this query do that binding instead:
// Responses the pack file responses.csv -> File.Contents(PackFolder & "responses.csv")
// Set PackFolder to the folder where you extracted the pack (keep the trailing backslash).
//
// Validated in the Power Query Exercises simulator (engine 0.1.0) against this pack's files; it returns
// 7 rows with columns RespondentID, Q1 Ease, Q2 Speed, Q3 Support, Q4 Recommend.
// It has not been run in Excel or Power BI by us. This is query text, not a ready-to-refresh workbook.
// Independent practice material; not affiliated with or endorsed by Microsoft.
let
PackFolder = "C:\PQE\survey-responses-pivot\",
Responses = File.Contents(PackFolder & "responses.csv"),
Source = Table.TransformColumnTypes(Table.PromoteHeaders(Csv.Document(Responses, [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv])), {{"Score", Int64.Type}}),
#"Questions" = List.Sort(List.Distinct(Source[Question])),
#"Pivoted" = Table.Pivot(Source, #"Questions", "Question", "Score", List.Max)
in
#"Pivoted"
Average score per question question-averages.pq
Download .pqAnswers and mean score per question. Returns 4 rows: Question, Answers, Average.
// Average score per question
// Pack: Survey responses (Power Query Exercises, https://powerqueryexercises.com/downloads/survey-responses-pivot)
//
// Source bindings
// In the Power Query Exercises simulator each name below is bound directly to a pack file. In Excel or
// Power BI Desktop the first steps of this query do that binding instead:
// Responses the pack file responses.csv -> File.Contents(PackFolder & "responses.csv")
// Set PackFolder to the folder where you extracted the pack (keep the trailing backslash).
//
// Validated in the Power Query Exercises simulator (engine 0.1.0) against this pack's files; it returns
// 4 rows with columns Question, Answers, Average.
// It has not been run in Excel or Power BI by us. This is query text, not a ready-to-refresh workbook.
// Independent practice material; not affiliated with or endorsed by Microsoft.
let
PackFolder = "C:\PQE\survey-responses-pivot\",
Responses = File.Contents(PackFolder & "responses.csv"),
Source = Table.TransformColumnTypes(Table.PromoteHeaders(Csv.Document(Responses, [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv])), {{"Score", Int64.Type}}),
#"Grouped" = Table.Group(Source, {"Question"}, {{"Answers", each Table.RowCount(_), Int64.Type}, {"Average", each Number.Round(List.Average([Score]), 2), type number}}),
#"Sorted" = Table.Sort(#"Grouped", {{"Question", Order.Ascending}})
in
#"Sorted"
Follow along in a host
Follow along in Excel
- Download the pack and extract the zip, for example to C:\PQE\<pack name>\.
- In Excel (Microsoft 365 or 2016+ on Windows), go to Data → Get Data → From Other Sources → Blank Query.
- In the Power Query Editor choose Home → Advanced Editor, select everything and paste the contents of the .pq file.
- Change the PackFolder line to the folder you extracted to, then choose Done.
- If Excel asks about privacy levels or file access, allow access to that folder. Then choose Home → Close & Load.
Follow along in Power BI Desktop
- Download the pack and extract the zip.
- In Power BI Desktop choose Home → Transform data to open the Power Query Editor, then Home → New Source → Blank Query.
- Choose Home → Advanced Editor, paste the contents of the .pq file and change the PackFolder line to your folder.
- Choose Done, check the preview against the expected rows in the query header, then Close & Apply.
Then try this
- Add a Q5 question for a few respondents and refresh: a Q5 column appears because the pivot values come from the data.
Related lessons
Original fictional data, free to use for learning and teaching. Power Query Exercises is not affiliated with or endorsed by Microsoft.