Use a Relative File Path for CSV Data in Excel Power Query
Question details
Use a CSV file from the same project folder as an Excel workbook without manually changing the Power Query source path for each project.

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- A workbook and its data.csv file are copied to separate project folders for reuse.
- Observed behavior
- File.Contents does not automatically resolve data.csv relative to the workbook, and a fixed absolute path can load data from an earlier project.
Save the workbook as an Excel file and place data.csv in the same folder. The folder formula below requires a saved workbook; verify its result after copying the files to a new project folder.
Read the workbook folder from a named cell in Power Query
Use a named cell to supply the current workbook folder and build the full CSV path when the query refreshes.
Power Query still passes a full path to File.Contents. The difference is that the folder portion comes from the workbook instead of being hard-coded in the query.
In a worksheet cell, enter =LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1))-1). Save the workbook and confirm the cell displays its folder path, including the trailing path separator.
Select the folder cell, type ProjectFolder in the Name Box to the left of the formula bar, and press Enter.
Go to Data > Get Data > From Other Sources > Blank Query, then open Home > Advanced Editor in Power Query. Paste this example: let Folder = Excel.CurrentWorkbook(){[Name="ProjectFolder"]}[Content]{0}[Column1], Source = Csv.Document(File.Contents(Folder & "data.csv"), [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv]) in Source. Select Done.
If the CSV has headers, select Home > Use First Row as Headers. Select Home > Close & Load, then use Data > Refresh All and check that the results match the CSV in the current project folder.

Work with Excel Files in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility to support migration. It does not fix Excel Power Query path behavior, and Power Query compatibility should be checked before migrating query-dependent workbooks.

Frequently Asked Questions
Why doesn't File.Contents("data.csv") use the workbook folder?
Power Query does not automatically interpret that relative path as being relative to the workbook. Provide a full path, such as one built from a named workbook folder cell and the CSV filename.
How do I use the folder cell in an existing query?
Open Data > Queries & Connections, edit the query, and use Home > Advanced Editor. Read the named cell with Excel.CurrentWorkbook, then replace the fixed path in File.Contents with the folder value combined with the filename.
What if the folder formula returns an error?
Save the workbook first, then recalculate the worksheet. CELL("filename",A1) needs a saved workbook to return a filename that the folder formula can extract.
How can I make sure the copied workbook uses the new project's CSV?
Open the copied workbook, recalculate and check the ProjectFolder cell, then select Data > Refresh All. Compare the loaded results with data.csv in the new folder.




