Add the Source File Name to Power Query Data in Excel
Question details
The user wants to add the source file name to each row of data imported with Power Query.

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- Combining files from a folder or importing a single file while preserving its name for traceability.
- Observed behavior
- Each imported row should include the name of the file it came from.
Confirm whether your query uses a folder connector or imports a single file. For a folder import, place the files to combine in the same folder and check that their data structures are compatible.
Retain file names when combining files from a folder
Use the folder listing's Name column to identify the source file for each combined row.
In Excel, select Data > Get Data > From File > From Folder, choose the folder, and select Transform Data.
In Power Query Editor, use the combine files button on the Content column and choose the table, sheet, or other data to import from the sample file.
In the combined query, inspect Applied Steps and keep the Name column from the folder listing. It may be renamed Source.Name during the combine process. If a step removes it, edit that step to retain it.
If the transformed tables are not already expanded, select the expand icon on the transformed-table column. Keep the file name column alongside the expanded data, rename it Source File if desired, and select Home > Close & Load.

Add a file name parameter to a single-file query
Use a parameter as a constant source label when a single-file connector does not provide a file name column.
Work with imported spreadsheet data in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for a smoother move between office suites. It does not fix or replace Excel Power Query's combine-files workflow.

Frequently Asked Questions
Where does the file name come from in a folder query?
The From Folder connector lists files with a Name column. Keep that column in the combined query so it remains beside the expanded data.
Why did the file name disappear after I combined the files?
An Applied Step may have removed the Name or Source.Name column. In Power Query Editor, inspect the steps and edit the step that removes columns so the file name is retained.
Can I rename Source.Name to something clearer?
Yes. In Power Query Editor, right-click the Source.Name column header, select Rename, and enter a name such as Source File.
Does a file name parameter update automatically when I change files?
Not if it is only a manually entered label. Use Home > Manage Parameters to update its value when the file changes, or use the parameter in the source setup to keep the reference and label aligned.




