Power Query Problems

Use a Relative File Path for CSV Data in Excel Power Query

Huma Ashraf ChHuma Ashraf Ch Nov 14, 2026 868 views

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.

Use a Relative File Path for CSV Data in Excel Power Query
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.
Before you start

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.

Solution 1Recommended

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.

1
Create the folder cell

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.

2
Name the cell

Select the folder cell, type ProjectFolder in the Name Box to the left of the formula bar, and press Enter.

3
Create the query

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.

4
Load and verify the data

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.

Read the workbook folder from a named cell in Power Query
Check the folder after copying: After opening a copied workbook, recalculate the worksheet and verify that ProjectFolder shows the new folder before selecting Data > Refresh All. Previously loaded data can remain visible until the query is refreshed.
Free Microsoft Office alternative

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.

Open and edit spreadsheet data in a familiar interfaceCompatible with Microsoft Excel formats such as XLSX and XLSUse a lightweight office suite for everyday document workMove between common Microsoft Office file formats
QA img-9

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.