Power Query Problems

Group Guest Stays into Columns in Excel with Power Query

Steven ParkerSteven Parker Dec 2, 2026 869 views

Question details

Transform multiple hotel-stay records per guest into one row with repeated stay details.

Group Guest Stays into Columns in Excel with Power Query
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the source table

Select a cell in Table1, then choose Data > From Table/Range to open Power Query Editor.

2
Replace the query

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

3
Load the result

Select Done, check the preview, and choose Home > Close & Load to place the grouped results in Excel.

4
Refresh after changes

After adding or editing rows in Table1, choose Data > Refresh All to update the grouped output.

Use Power Query to create one row per guest
Match the column names: The query uses the exact table and column names listed above. Rename your source fields or edit the names in the code if yours differ.
Free Microsoft Office alternative

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.

Review guest names, dates, properties, and room types in spreadsheetsOpen and edit Microsoft Excel XLSX filesWork in a familiar spreadsheet interfaceUse a free, lightweight Office alternative
microsoft office alternative - wps office

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.