Power Query Problems

Use Excel Power Query to Split and Append Employee Record Groups

Algirdas JasaitisAlgirdas Jasaitis Nov 22, 2026 870 views

Question details

Split wide employee data into variable-length record groups and append the groups for routing by record type.

Split and Append Employee Record Groups with Excel Power Query
Product
Microsoft Excel Power Query
Device & OS
not provided
Scenario
An employee data file contains an unknown number of personal, address, job, and other record groups, each identified by a record-type indicator.
Observed behavior
The user wants to process approximately 120 employees automatically rather than manually adding record breaks.
Before you start

Identify a reliable rule for recognizing every record-type indicator, including the employee-number indicator. Confirm whether each source row represents one employee and whether indicator values can also appear in ordinary data; the example below assumes one employee per row and unambiguous indicator values.

Solution 1Recommended

Generate and append record groups with Power Query M

Use this approach when indicator values reliably mark group boundaries and groups can contain different numbers of fields.

The example converts each group into rows containing the source row number, record type, field position, and field value. This long format lets groups with different field counts be appended without assuming fixed column positions.

Replace the example indicator values with the actual values or a reliable detection rule. If indicators cannot be distinguished from ordinary data, the source format needs additional boundary information before it can be split reliably.

1
Prepare the source table

In Excel, select the employee data and choose Insert > Table. On the Table Design tab, name the table EmployeeData. Each row must contain one employee for this example.

2
Open a blank query

Choose Data > Get Data > From Other Sources > Blank Query, then open Home > Advanced Editor.

3
Enter the M query

Replace the editor contents with the query below. Change EMPLOYEE, PERSONAL, ADDRESS, and JOB to the actual indicator values, adding all other valid record types. The query treats every cell after an indicator and before the next indicator as a field in that group. let Source = Excel.CurrentWorkbook(){[Name="EmployeeData"]}[Content], Rows = Table.ToRows(Source), Markers = {"EMPLOYEE", "PERSONAL", "ADDRESS", "JOB"}, IsMarker = (value as any) as logical => List.Contains(Markers, value), GroupTables = List.Combine( List.Transform(List.Positions(Rows), (r) => let Row = Rows{r}, Positions = List.Select(List.Positions(Row), (p) => IsMarker(Row{p})), Groups = List.Generate( () => 0, (i) => i < List.Count(Positions), (i) => i + 1, (i) => let Start = Positions{i}, End = if i + 1 < List.Count(Positions) then Positions{i + 1} else List.Count(Row), Fields = List.Range(Row, Start + 1, End - Start - 1), Records = List.Transform(List.Positions(Fields), (f) => [EmployeeRow = r + 1, RecordType = Row{Start}, FieldPosition = f + 1, FieldValue = Fields{f}]) in Table.FromRecords(Records, {"EmployeeRow", "RecordType", "FieldPosition", "FieldValue"}, MissingField.UseNull) ) in Groups ) ), Result = if List.IsEmpty(GroupTables) then #table({"EmployeeRow", "RecordType", "FieldPosition", "FieldValue"}, {}) else Table.Combine(GroupTables) in Result

4
Check and route the results

Select Done and inspect the preview. Use the RecordType filter to select a destination type; right-click the query and choose Reference to create separate filtered queries for personal, address, job, and other records. Use Home > Close & Load when the results are ready.

Generate and append record groups with Power Query M
Check the output structure: EmployeeRow is the source row's position, not the employee number. The employee-number indicator and its fields remain in the output if included in Markers. Empty groups produce no field rows, and cells before the first recognized indicator are ignored. Map field positions to destination columns as needed.
Free Microsoft Office alternative

Review employee spreadsheets with WPS Office

WPS Office is a free, lightweight Microsoft Office alternative with a familiar spreadsheet interface. Open compatible Excel files and move between office suites easily when reviewing employee data; it does not fix or replace the Excel Power Query workflow described here.

Review and filter employee data in WPS SpreadsheetsCompatible with Microsoft Excel XLS and XLSX formatsFamiliar spreadsheet interface for an easier transitionFree and lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

How does the query handle an unknown number of groups?

List.Generate creates a table for each detected group in a source row. Table.Combine then appends the generated tables without requiring a fixed group count.

What if record types have different numbers of fields?

The example stores each field on its own row with a FieldPosition. Filter by RecordType and map those positions to the destination table's columns.

Can Power Query identify indicators if their values change?

Only if there is another reliable rule or source of metadata that distinguishes indicators from ordinary values. Update the IsMarker function in Advanced Editor to use that rule; column position alone is not reliable when group widths vary.

How do I keep the employee number with each record type?

Include the employee-number indicator in Markers and use EmployeeRow to associate its fields with the other groups from the same source row. Add a merge or transformation in Power Query if each destination row must contain the employee number itself.

Does this query insert line breaks into the original file?

No. It creates a transformed Power Query result. Use Close & Load to place the result in a worksheet, then apply any additional formatting or export steps required by the receiving system.