Forum Discussion
Anonymous
4 years agoNot applicable
Survey Question & Answer from rows to column and rows
Hi all, I am stuggling to figure out how to get my survey answers as preferred. I have two columns: Column1 is the question and Column2 is the answer. I want a table where the question is th...
- 4 years ago
Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)
Solution using Transpose
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc6hEcAwDATBXoQN8pIlJzAlBHvcfxu2IvLs0M7NKR+kyQtZ7bRma7VlW3XP7tWe7dWRHdW/M8i5yXnIwUUQQBKUKBhZ6ITBWQvWBmtnYG0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]), #"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Temp", each Text.Combine([Column2],";"), type nullable text}}), #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Temp", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Temp.1", "Temp.2", "Temp.3"}), #"Transposed Table" = Table.Transpose(#"Split Column by Delimiter"), #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]) in #"Promoted Headers"Solution using Pivots
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc6hEcAwDATBXoQN8pIlJzAlBHvcfxu2IvLs0M7NKR+kyQtZ7bRma7VlW3XP7tWe7dWRHdW/M8i5yXnIwUUQQBKUKBhZ6ITBWQvWBmtnYG0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]), #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type), #"Inserted Division" = Table.AddColumn(#"Added Index", "Division", each [Index] / 6, type number), #"Inserted Round Up" = Table.AddColumn(#"Inserted Division", "Round Up", each Number.RoundUp([Division]), Int64.Type), #"Removed Columns" = Table.RemoveColumns(#"Inserted Round Up",{"Index", "Division"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Column1]), "Column1", "Column2"), #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Round Up"}) in #"Removed Columns1"
Vijay_A_Verma
4 years agoMost Valuable Professional
Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)
Solution using Transpose
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc6hEcAwDATBXoQN8pIlJzAlBHvcfxu2IvLs0M7NKR+kyQtZ7bRma7VlW3XP7tWe7dWRHdW/M8i5yXnIwUUQQBKUKBhZ6ITBWQvWBmtnYG0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
#"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Temp", each Text.Combine([Column2],";"), type nullable text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Temp", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Temp.1", "Temp.2", "Temp.3"}),
#"Transposed Table" = Table.Transpose(#"Split Column by Delimiter"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true])
in
#"Promoted Headers"Solution using Pivots
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc6hEcAwDATBXoQN8pIlJzAlBHvcfxu2IvLs0M7NKR+kyQtZ7bRma7VlW3XP7tWe7dWRHdW/M8i5yXnIwUUQQBKUKBhZ6ITBWQvWBmtnYG0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
#"Inserted Division" = Table.AddColumn(#"Added Index", "Division", each [Index] / 6, type number),
#"Inserted Round Up" = Table.AddColumn(#"Inserted Division", "Round Up", each Number.RoundUp([Division]), Int64.Type),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Round Up",{"Index", "Division"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Column1]), "Column1", "Column2"),
#"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Round Up"})
in
#"Removed Columns1"
Anonymous
4 years agoNot applicable
Hi Vijay,
Thank you so much. Been struggling, but you make it look easy 😉
Regards,
Jur