Group Guest Stays into Columns in Excel with Power Query
Question details
Transform multiple hotel-stay records per guest into one row with repeated stay details.

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- A hotel-stay table contains multiple rows for each guest, with property, arrival, departure, and room type details.
- Observed behavior
- The desired output has one row per guest, with a separate set of stay-detail columns for each visit.
Format the source data as an Excel table named Table1 with columns named Guest Name, Property, Arrival, Departure, and Room Type. Make sure Arrival values are actual dates so the stays can be sorted chronologically.
Use Power Query to create one row per guest
Use this method to generate repeated stay-detail columns for every guest and refresh the result when the source table changes.
The query groups records by guest, sorts each guest's stays by arrival date, and numbers the stays. Guests with fewer stays have blank cells in the extra columns.
Select a cell in Table1, then choose Data > From Table/Range to open Power Query Editor.
In Power Query Editor, select Home > Advanced Editor. Replace the existing code with: let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], Grouped = Table.Group(Source, {"Guest Name"}, {{"Stays", each Table.AddIndexColumn(Table.Sort(_, {{"Arrival", Order.Ascending}}), "Stay", 1, 1, Int64.Type)}}), AddedFields = Table.AddColumn(Grouped, "Fields", each List.Accumulate(Table.ToRecords([Stays]), [], (state, stay) => Record.Combine({state, Record.FromList({stay[Property], stay[Arrival], stay[Departure], stay[Room Type]}, List.Transform({"Property", "Arrival", "Departure", "Room Type"}, (field) => field & " " & Text.From(stay[Stay])))}))), Records = List.Transform(Table.ToRecords(AddedFields), (r) => Record.Combine({Record.FromList({r[Guest Name]}, {"Guest Name"}), r[Fields]})), Columns = List.Union(List.Transform(Records, each Record.FieldNames(_))), Result = Table.FromRecords(Records, Columns, MissingField.UseNull) in Result
Select Done, check the preview, and choose Home > Close & Load to place the grouped results in Excel.
After adding or editing rows in Table1, choose Data > Refresh All to update the grouped output.

Filter and sort stays for one guest with a formula
Use this option when you only need to inspect one guest at a time; it returns stays as rows rather than repeated column groups.
Review hotel-stay spreadsheets with WPS Office
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface. Open compatible Excel files to review and edit guest-stay data as you migrate your everyday spreadsheet work.

Frequently Asked Questions
How do I update the grouped table when new stays are added?
Add the records to Table1, then select Data > Refresh All in Excel. The Power Query output will be regenerated.
What happens if one guest has more stays than another?
The Power Query result includes columns for the largest number of stays found. Guests with fewer stays have blank cells in the remaining stay columns.
Why is the single-guest formula sorting by the wrong column?
The value 3 in SORT refers to the third column of Table1. Change it to the position of the Arrival column, and make sure arrival values are stored as dates.
Does the FILTER formula create one row per guest?
No. Entering the formula in an empty cell returns the selected guest's stays as multiple rows. Use the Power Query method to create repeated stay columns on one row.




