Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
N-msft
Frequent Visitor

How to transfrom questionaire responses into separate columns

Hi I have a table that contains responses for their respective quesions on a scale of 1 to 5 as below :  

 

IDResponses
1001Q1-3 | Q2-5 | Q3-4 | Q4-2 | Q5-5
1002Q1-3 | Q2-4 | Q3-4 | Q4-4 | Q5-3
1003Q1-3 | Q2-2 | Q3-4 | Q4-2 | Q5-1
1004Q1-3 | Q2-1 | Q3-4 | Q4-2 | Q5-5

 

How can I transform these responses in power query as :

 

IDQ1Q2Q3Q4Q5
100135425
100234443
100332421
100431425

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

In Power Query

1. Split Responses by delimiter "|"

jdbuchanan71_0-1692545956395.png

Select ID and Unpivot other columns

jdbuchanan71_1-1692546013796.png

Remove the attribute column and trim the Value column then split the Value column by delimeter "-"

jdbuchanan71_2-1692546085493.png

Select the Value.1 column and pitvot the column with Value.2 using no aggregation.

jdbuchanan71_3-1692546178075.png

And you end up with this.

jdbuchanan71_4-1692546219302.png

 

Here is the code from the advanced editor for all the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUQo01DVWqFEINNI1BVHGuiYgykTXCESZ6poqxeqA1RqhqDVBUWsCUWsMU2uMotYIm7mGMLUmKGoNcbghFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Responses = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Responses", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Responses", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Responses.1", "Responses.2", "Responses.3", "Responses.4", "Responses.5"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"ID"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Trimmed Text" = Table.TransformColumns(#"Removed Columns",{{"Value", Text.Trim, type text}}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Trimmed Text", "Value", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Value.1", "Value.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter1", List.Distinct(#"Split Column by Delimiter1"[Value.1]), "Value.1", "Value.2")
in
    #"Pivoted Column"

 

 

View solution in original post

2 REPLIES 2
N-msft
Frequent Visitor

Thank you so much.

jdbuchanan71
Super User
Super User

In Power Query

1. Split Responses by delimiter "|"

jdbuchanan71_0-1692545956395.png

Select ID and Unpivot other columns

jdbuchanan71_1-1692546013796.png

Remove the attribute column and trim the Value column then split the Value column by delimeter "-"

jdbuchanan71_2-1692546085493.png

Select the Value.1 column and pitvot the column with Value.2 using no aggregation.

jdbuchanan71_3-1692546178075.png

And you end up with this.

jdbuchanan71_4-1692546219302.png

 

Here is the code from the advanced editor for all the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUQo01DVWqFEINNI1BVHGuiYgykTXCESZ6poqxeqA1RqhqDVBUWsCUWsMU2uMotYIm7mGMLUmKGoNcbghFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Responses = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Responses", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Responses", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Responses.1", "Responses.2", "Responses.3", "Responses.4", "Responses.5"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"ID"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Trimmed Text" = Table.TransformColumns(#"Removed Columns",{{"Value", Text.Trim, type text}}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Trimmed Text", "Value", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Value.1", "Value.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter1", List.Distinct(#"Split Column by Delimiter1"[Value.1]), "Value.1", "Value.2")
in
    #"Pivoted Column"

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors