Power Query Problems

Import a CSV from the Workbook Folder with Excel Power Query

Chanuka GeekiyanageChanuka Geekiyanage Dec 2, 2026 868 views

Question details

Create a Power Query source that imports a CSV from the folder containing the Excel workbook without hard-coding the full path.

Import a CSV from the Workbook Folder with Excel Power Query
Product
Microsoft Excel Power Query
Device & OS
not provided
Scenario
The workbook and a CSV file may be moved together to a different folder.
Observed behavior
The query should use the workbook’s folder and the specified CSV file name when refreshed.
Before you start

Save the workbook and place the CSV in the same folder. Note the CSV’s exact file name, including its extension, and check that the CELL formula below returns the workbook folder.

Solution 1Recommended

Use a named cell to pass the workbook folder to Power Query

Use this method when the workbook and CSV will stay together but their folder path may change.

Unlike INFO("DIRECTORY"), which returns the current working directory, the CELL formula below derives the path from the saved workbook’s location.

The example assumes a comma-delimited UTF-8 CSV named data.csv. Adjust the file name and import options to match your file.

1
Create the folder formula

In cell B1, enter =LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1))-1). Confirm that the result is the saved workbook’s folder path, including its trailing separator.

2
Name the path cell

Select B1, click the Name Box to the left of the formula bar, type WorkbookFolder, and press Enter. Save the workbook.

3
Create a path query

Choose Data > Get Data > From Other Sources > Blank Query. In Power Query Editor, open Home > Advanced Editor and enter: let Source = Excel.CurrentWorkbook(){[Name="WorkbookFolder"]}[Content]{0}[Column1] in Source. Name the query WorkbookFolder, then use Close & Load To > Only Create Connection.

4
Import the CSV

Choose Data > From Text/CSV, select the CSV, and click Transform Data. In Power Query Editor, select the Source applied step and replace its formula in the formula bar with = Csv.Document(File.Contents(WorkbookFolder & "data.csv"), [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv]). Replace data.csv with your actual file name.

5
Load and refresh

Check the preview and adjust any later applied steps if needed. Choose Home > Close & Load To to load the result to a worksheet or, if needed, select Add this data to the Data Model. After moving the files, open the workbook, recalculate the folder formula, and use Data > Refresh All.

Use a named cell to pass the workbook folder to Power Query
If a Formula.Firewall error appears: In Power Query Editor, open File > Options and Settings > Data Source Settings or Query Options and review the privacy levels for the workbook and CSV sources. Ignoring privacy levels can expose data between sources, so use that option only if you understand and accept the risk.
Free Microsoft Office alternative

Work with Excel and CSV files in WPS Spreadsheets

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for working with Excel and CSV files. It can help you move everyday spreadsheet work to WPS, although it does not fix Microsoft Excel Power Query or guarantee that Power Query connections will work unchanged.

Open and edit CSV data in a spreadsheetCompatible with Microsoft Excel XLSX and XLS filesFamiliar interface for everyday spreadsheet tasksFree and lightweight for an easier transition from Office
microsoft office alternative - wps office

Frequently Asked Questions

Why not use INFO("DIRECTORY") for the workbook folder?

INFO("DIRECTORY") returns the current working directory, which is not necessarily the folder containing the workbook. The CELL("filename",A1) formula derives the folder from the saved workbook’s location.

Why does the folder formula return an error?

The workbook must be saved before CELL("filename",A1) can return its path. Save it with File > Save, then recalculate the worksheet and check the formula cell.

How do I change the CSV file name?

In Power Query Editor, select the CSV query’s Source step and replace "data.csv" in the formula bar with the exact file name, including the .csv extension.

What should I do after moving the workbook and CSV?

Keep both files in the same folder, open the workbook from its new location, and recalculate the folder formula. Check that it shows the new path, then select Data > Refresh All.

Do I have to add the query to the Data Model?

No. In Close & Load To, choose the destination that suits your workbook. Add the data to the Data Model only if you need it there.