Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I have on column that has some duplicate ID's that I am trying to pivot from long to wide
| ID's | Questions |
| A | q1 |
| A | q2 |
| B | q3 |
| B | q4 |
| B | q5 |
| C | q6 |
| D | q7 |
| D | q8 |
| E | q9 |
taking this data set to make it look like this
| ID's | Q variant 1 | Q variant 2 | Q variant 3 |
| A | q1 | q2 | null |
| B | q3 | q4 | q5 |
| C | q6 | null | null |
| D | q7 | q8 | null |
| E | q9 | null | null |
I do not know how to do it but I was thinking of making a reference column corresponding to which column the question needed to be in then pivot with the reference column being the header
ie
| ID | Question | reference |
| A | q1 | 1 |
| A | q2 | 2 |
| B | q3 | 1 |
| B | q4 | 2 |
| B | q5 | 3 |
any help or suggestions would be appriciated
Thank you
Solved! Go to Solution.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUSo0VIrVgTKNwEwnENMYwTRBME3BTGcQ0wzMdAExzRFMCzDTFcS0VIqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"ID's" = _t, #"Questions " = _t]),
RenamedColumns = Table.RenameColumns(Source, {{"Questions ", "Questions"}}),
SortedTable = Table.Sort(RenamedColumns, {{"ID's", Order.Ascending}, {"Questions", Order.Ascending}}),
GroupedTable = Table.Group(SortedTable, {"ID's"}, {{"AllData", each Table.AddIndexColumn(_, "Reference", 1, 1, Int64.Type)}}),
ExpandedTable = Table.ExpandTableColumn(GroupedTable, "AllData", {"Questions", "Reference"}),
ConvertedReference = Table.TransformColumnTypes(ExpandedTable, {{"Reference", type text}}),
PivotedTable = Table.Pivot(ConvertedReference, List.Distinct(ConvertedReference[Reference]), "Reference", "Questions"),
RenamedPivotedColumns = Table.RenameColumns(PivotedTable, {{"1", "Q variant 1"}, {"2", "Q variant 2"}, {"3", "Q variant 3"}})
in
RenamedPivotedColumns
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUSo0VIrVgTKNwEwnENMYwTRBME3BTGcQ0wzMdAExzRFMCzDTFcS0VIqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"ID's" = _t, #"Questions " = _t]),
RenamedColumns = Table.RenameColumns(Source, {{"Questions ", "Questions"}}),
SortedTable = Table.Sort(RenamedColumns, {{"ID's", Order.Ascending}, {"Questions", Order.Ascending}}),
GroupedTable = Table.Group(SortedTable, {"ID's"}, {{"AllData", each Table.AddIndexColumn(_, "Reference", 1, 1, Int64.Type)}}),
ExpandedTable = Table.ExpandTableColumn(GroupedTable, "AllData", {"Questions", "Reference"}),
ConvertedReference = Table.TransformColumnTypes(ExpandedTable, {{"Reference", type text}}),
PivotedTable = Table.Pivot(ConvertedReference, List.Distinct(ConvertedReference[Reference]), "Reference", "Questions"),
RenamedPivotedColumns = Table.RenameColumns(PivotedTable, {{"1", "Q variant 1"}, {"2", "Q variant 2"}, {"3", "Q variant 3"}})
in
RenamedPivotedColumns
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 59 | |
| 43 | |
| 42 | |
| 23 | |
| 17 |
| User | Count |
|---|---|
| 190 | |
| 122 | |
| 96 | |
| 66 | |
| 47 |