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

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.

Reply
PhDWoes
New Member

Transforming data from two columns into sample grouped columns

Hello to all, 

 

I am a new adventurer into data analysis, and want to learn how to use Excel more efficiently. 

What I want to do is shown below - to change my existing data from 2 columns that list the name of the sample and its measurements, to a table where each sample is its own column with its measurements listed below it in rows. It's imperative that the measurements stay in their order. 

PhDWoes_0-1760438904554.png

I have tried to use Powerquery, but most I can do is Group the samples by their name - but this only gives me a link to table that shows the measurements for that sample. 

All help is appreciated! 

 

Best regards,

PhD Student 

1 ACCEPTED SOLUTION
tayloramy
Community Champion
Community Champion

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 Support

 

 

If 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

View solution in original post

5 REPLIES 5
v-hashadapu
Community Support
Community Support

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.

wdx223_Daniel
Super User
Super User

NewStep=let a=Table.Group(YourTable,"Sample",{"n",each [Measurement]}) in Table.FormColumns(a[n],a[Sample])

m_dekorte
Super User
Super User

Alternatively, you could  group and collect columns and names, like so

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc4pEoAwEEXBu4yOYQfJfM0JUhGISBAs96cqNk9gW3WMtlqwLe/3e+Ujn09jKVTYEnaEPeFAOBJOhHNBp6fT0+np9HR6Oj2dnv7juRQU5UV5UV6UF+VFeVFelFeVTx8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Sample = _t, Measurement = _t]),
    GroupRows = Table.Group(Source, {"Sample"}, {{"Measurement", each [Measurement]}}),
    ToTable = Table.FromColumns(GroupRows[Measurement], GroupRows[Sample])
in
    ToTable
tayloramy
Community Champion
Community Champion

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 Support

 

 

If 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

Thank you so much for the help! Adding the per-sample index fixed my issues, and saved me days of work! 🙂

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors