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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
SJG
New Member

Combining Multiple Columns to One

Hello,

 

I have survey data that comes in a pretty poor format and need assistance reformatting. When a question is asked multiple times in the survey, each response is placed in a new column. An example question is, "What Position are you At?" Each reponse from the person performing the survey creates a columns. I need a way to put all the columns of data into 1 long column. I will provide an example below. Is this possible?

 

PersonPositionPosition2Position3
A123
B123
C123

 

Needs turned into:

 

Position

1
2
3
1
2
3
1
2
3
1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

Yes it is possible.

 

Here is the M Query code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYiMgNlaK1YlWcsIQcUYViQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, Position = _t, Position2 = _t, Position3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Person", type text}, {"Position", Int64.Type}, {"Position2", Int64.Type}, {"Position3", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Person"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute", "Person"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value", "Position"}})
in
    #"Renamed Columns"

 

Your source:

sevenhills_0-1685126198976.png

 

 

Output:

sevenhills_1-1685126213234.png

 

View solution in original post

1 REPLY 1
sevenhills
Super User
Super User

Yes it is possible.

 

Here is the M Query code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYiMgNlaK1YlWcsIQcUYViQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, Position = _t, Position2 = _t, Position3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Person", type text}, {"Position", Int64.Type}, {"Position2", Int64.Type}, {"Position3", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Person"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute", "Person"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value", "Position"}})
in
    #"Renamed Columns"

 

Your source:

sevenhills_0-1685126198976.png

 

 

Output:

sevenhills_1-1685126213234.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.