Forum Discussion
Transforming data from two columns into sample grouped columns
- 9 months ago
Hi PhDWoes,
You’re describing a classic Power Query reshape: take a 2-column list like [Sample, Measurement] and “pivot” it so each Sample becomes a separate column, with the measurements stacked in order down the rows. The key to preserving order is to create a per-Sample index first, then pivot on Sample using that index as the row key.
See this link for guidance:
Pivot columns (Power Query) - Microsoft SupportIf you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.
~Taylor Amy
Hi PhDWoes , Thank you for reaching out to the Microsoft Community Forum.
tayloramy is correct, creating a per-sample index to preserve the order of measurements and then performing a pivot on the Sample column using that index as the row key is the best approach. This ensures each sample becomes its own column with measurements aligned correctly. To complete the solution, it’s worth noting that in Power Query you can add the per-sample index by grouping the data first, adding an index column within each group and then expanding and pivoting. This extra step guarantees that even if the source data changes or new measurements are added, the order is maintained accurately across all samples.
Table.Pivot - PowerQuery M | Microsoft Learn
Pivot columns (Power Query) - Microsoft Support
Thank you tayloramy for your valuable response.