How to Combine Two Student Rows into One Excel Row
Question details
The user needs a method to consolidate data where each student has two separate rows, moving the data from the second row into additional columns of the first row to create a single, comprehensive record per student.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Reorganizing poorly structured student records where information is split across two rows instead of a single consolidated row.
- Observed behavior
- Currently, student data is fragmented into multiple rows, making it difficult to analyze. The goal is to append the second row's data into new columns on the first row's level.
Ensure your data is sorted by student name or ID so that the two rows for each student appear consecutively, and create a backup of your worksheet to prevent accidental data loss during formula application.
Use XLOOKUP and COUNTIF to Retrieve the Second Row
This method uses XLOOKUP's bottom-up search feature combined with COUNTIF to fetch the second occurrence of a student's record and place it alongside the first.
This approach is highly effective if every student appears exactly twice in your dataset. By setting XLOOKUP's search mode to -1, you instruct Excel to search from the bottom of the array up, effectively grabbing the second row's data.
Create new column headers next to your first set of data (e.g., starting in column M) to hold the values you want to retrieve from the second row.
In the first cell of your new columns (e.g., M2), type the formula: =IF(COUNTIF($A$2:$A2,$A2)=1,XLOOKUP($A2,$A$2:$A$11,G$2:G$11,,0,-1),""). Adjust the column references so column A points to the student ID and column G points to the data you want to retrieve.
Press Enter to execute the formula. Then, click the small square at the bottom-right corner of the cell (fill handle) and drag it across the columns and down the rows to populate the data for all students.

Consolidate Rows using Microsoft 365 Dynamic Arrays
If you are using Microsoft 365, you can use a complex dynamic array formula that automatically spills the combined results without the need to drag across cells manually.
Combine Multiple Rows Efficiently with WPS Spreadsheet
WPS Spreadsheet offers comprehensive support for advanced lookup functions like XLOOKUP, allowing you to easily consolidate duplicated records, merge rows, and manage complex datasets with zero hassle.
- 1. Open your document: Launch WPS Spreadsheet and open the workbook containing your fragmented student data.
- 2. Apply the XLOOKUP formula: In an empty column adjacent to your data, enter the recommended XLOOKUP and COUNTIF combination formula.
- 3. Drag to fill: Use the smart fill handle to apply the formula down the column, instantly merging the student records side-by-side.
- 4. Filter and clean: Navigate to the 'Data' tab and use the 'Filter' tool to hide or remove the now-redundant secondary rows.

Frequently Asked Questions
Can I combine rows without using complex formulas?
Yes, if you prefer not to use formulas, you can use the Power Query feature. Load your table into Power Query, group the data by the student ID or name, and then pivot the data to flatten the rows into a single record.
Why is my XLOOKUP formula returning an error?
Ensure that your data ranges are locked using absolute references (like $A$2:$A$11). If the ranges are not locked, they will shift when you drag the formula down or across, resulting in #N/A or #VALUE! errors.
How do I remove the empty or duplicate rows after consolidating?
Once you have successfully merged the data into new columns, copy the entire new data range and paste it back over itself as 'Values' (Right-click > Paste Special > Values) to remove the formulas. You can then sort the data or use the 'Remove Duplicates' feature under the Data tab to safely delete the older, fragmented rows.
What if a student has three rows instead of two?
The standard XLOOKUP formula with a -1 search mode is designed to find only the last (second) entry. If a student has three or more rows, you will need to use a FILTER function wrapped in TRANSPOSE to spill all matching records horizontally across columns.




