How to Use Power Query to Sort People and Associated Numbers
Question details
The user needs to extract multiple people's names stored in a single cell, match them with their associated numbers, and create a structured table organized by person.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Reorganizing messy datasets where multiple people and numbers are combined in single cells, requiring a structured layout for each person.
- Observed behavior
- The goal state is a cleanly pivoted data table where each person has their own dedicated column or row listing all their associated numbers.
Ensure your dataset is formatted as a Table (Ctrl+T) before importing it into Power Query, and identify the exact delimiter (such as a comma, space, or line break) separating the names.
Split and Pivot Data using Power Query Editor
Use Power Query's built-in split, group, and pivot features to automatically restructure combined cell data into individual columns per person.
By utilizing Power Query, you can automate the process of separating grouped names and matching them to their corresponding numbers. This is especially helpful if the cells in your Person column contain line breaks or custom delimiters.
Select your data range and click Data > From Table/Range on the ribbon to open the Power Query Editor.
Select the Person column, go to Home > Split Column > By Delimiter. Choose your delimiter (for line breaks, choose Custom and type #(lf)) and under Advanced Options, select to split into Rows.
Navigate to the Add Column tab and click Index Column > From 1. This step is crucial to prevent aggregation errors when dealing with duplicate numbers.
Select your Person column, go to Transform > Pivot Column. In the Values Column dropdown, select your Numbers column. Open Advanced options and select 'Don't Aggregate', then click OK.
Click Home > Close & Load to output your freshly sorted and pivoted table back into a new worksheet.

Looking for a Lightweight Tool for Complex Data Sorting?
While Power Query is a specific feature of Microsoft Excel, WPS Office provides a free, highly compatible, and user-friendly alternative for managing your spreadsheets. Easily split text, sort data, and create pivot tables to manage complex records without writing advanced code.
- 1. Download and Install: Get WPS Office for free from the official website and install it on your device.
- 2. Open Your Spreadsheet: Launch WPS Spreadsheet and open your existing Excel (.xlsx) files directly with zero format loss.
- 3. Manage Data Easily: Use the Data tab to access Text to Columns, sorting tools, and Pivot Tables to organize your records seamlessly.

Frequently Asked Questions
How do I handle line breaks inside a cell when splitting data in Power Query?
When using the 'Split Column by Delimiter' feature in Power Query, choose 'Custom' as your delimiter and type '#(lf)' (without quotes). This M-code syntax specifically targets line feeds (line breaks) within cells.
Why does Table.Pivot result in errors for duplicate values?
If multiple identical numbers are associated with the same person, pivoting without an index can cause aggregation errors. Adding an Index Column before pivoting ensures that every row has a unique identifier, allowing 'Don't Aggregate' to function correctly.
How do I update my pivoted table when I add new names or numbers?
You do not need to rebuild the query from scratch. Simply add your new data to the original source table, navigate to the Data tab in your workbook, and click 'Refresh All' to automatically apply the splitting and pivoting steps to the new data.




