Excel Power Query: Preserve Manual Categories When Refreshing Folder Queries
Question details
The user needs to preserve manually assigned categories when an Excel Power Query folder query is refreshed with new files.

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- A folder query imports files, and manual category values are maintained beside the query output while additional files are added over time.
- Observed behavior
- Refreshing the query can reorder or replace output rows, causing manually entered categories to become associated with the wrong files.
Identify a stable unique key for every file, such as the full filename or a file ID, and ensure it is included in the query output. Keep the manual category values in a separate table with a unique key column and a category column.
Merge a separate category mapping table into the refreshed folder query
Use this recommended approach when categories must remain attached to the correct files after new files are added or query rows are reordered.
A manually entered column beside a Power Query result is not reliably synchronized with refreshed rows. Store categories separately and join them to the query by a stable filename or other unique identifier.
In Excel, create a table containing one unique filename or file ID per row and its corresponding category. Select the range and choose Insert > Table, then give the table a clear name such as CategoryMap.
Select any cell in the category table and choose Data > From Table/Range. In Power Query Editor, confirm that the key and category columns have the correct data types, then select Home > Close & Load To and load it as a connection.
Select Data > Queries & Connections, right-click the folder query, and choose Edit to open it in Power Query Editor. Confirm that the output includes the same filename or unique ID used by CategoryMap.
In Power Query Editor, select Home > Merge Queries, choose the folder query and CategoryMap, select the matching filename or ID columns in both tables, and use a Left Outer join.
Select the expand button on the merged CategoryMap column, keep the category field, and choose Home > Close & Load. Later, add or update categories only in CategoryMap and select Data > Refresh All.
Use a stable key with a lookup after the query loads
Use this option when you prefer to keep the category mapping in an Excel worksheet rather than adding the merge step inside Power Query.
Build a self-referencing Power Query design for managed category data
Use this advanced option when the category information must remain within the Power Query workflow and the workbook is maintained by experienced query users.
Try WPS Office for Lightweight Spreadsheet Work and Excel File Compatibility
WPS Office is a free, lightweight alternative for opening, editing, and sharing common Excel workbooks. Its familiar spreadsheet interface and compatibility with Microsoft Office formats make migration easy, although Excel Power Query-specific workflows should remain in Excel.
- 1. Download WPS Office: Select Download WPS Office Free and install the application for your device.
- 2. Open the workbook: In WPS Spreadsheet, choose Menu > Open and select the .xlsx, .xls, or .csv workbook you want to review.
- 3. Maintain the category mapping: Create or edit a separate mapping table with stable filenames and categories, then use spreadsheet lookup functions to relate categories to refreshed data.

Frequently Asked Questions
Why do manual categories move to the wrong files after a folder query refresh?
Power Query can add, remove, or reorder rows during a refresh. A manually typed value beside the output is tied to the row position, not to the file identity, so it can become associated with another file.
What key should I use to preserve categories in Power Query?
Use a value that remains unique and stable, such as the complete filename or a generated file ID. Avoid relying only on the row number because refresh operations can change row order.
Where should I store categories for a Power Query folder import?
Store them in a separate Excel table with one key column and one category column. Load that table into Power Query and use Home > Merge Queries to join it to the folder output.
Can I use XLOOKUP instead of merging the category table in Power Query?
Yes. After the query loads, add an XLOOKUP column that matches the refreshed filename or ID against the separate category table. This works when the output includes the matching key and the mapping keys are unique.
Should I type categories directly into the Power Query results?
No. Query output can be replaced or reordered during refresh, and manually entered cells are not reliably preserved. Maintain editable categories in a separate mapping table or use a carefully designed self-referencing query.




