How to Change Data Source Path in Power BI
Nothing stops a Power BI project in its tracks faster than a moved file. One moment your report is working perfectly, and the next, you’re staring at a refresh error because the source Excel file was moved from your Downloads folder to a shared SharePoint site. This article will show you exactly how to change the data source path in Power BI, covering the simple, direct method and a more powerful, dynamic approach using parameters.
Why Do Data Source Paths Need to Be Changed?
Before we get into the "how," let's quickly cover the "why." You'll inevitably need to update a source path when:
- A file moves. This is the most common reason. You might start a report using a file on your Desktop, but it later moves to a shared server, OneDrive, or SharePoint folder for team access.
- You switch environments. Developers often build reports using a test or development database. When the report is ready for production, they need to point it to the live production database server.
- The folder structure changes. A company re-org or a server migration can change the location of all your source files, requiring you to update your reports.
- Data is archived. You might update your report from pointing at
Sales_2023.csvtoSales_2024.csv.
Whatever the reason, being able to quickly update the source is a fundamental Power BI skill.
Method 1: The Direct Approach (Best for Quick Fixes)
This is the simplest way to update the path for a single file source like an Excel, CSV, or text file. It’s perfect for a one-time fix.
Step-by-Step Instructions:
- Open the Power Query Editor: First, open your Power BI Desktop (.pbix) file. In the "Home" ribbon, click the Transform data button. This will launch the Power Query Editor, which is where all data transformation and connection logic lives.
- Select Your Query: On the left side of the Power Query Editor, you’ll see a list of all your queries (your data tables). Select the query whose data source has moved.
- Access the Source Step: On the right side, in the "Query Settings" pane, you’ll see a list of "APPLIED STEPS." The very first step is almost always named Source. Click the small gear icon (⚙️) next to it.
- Change the File Path: A dialog box will appear, showing you the connection details. For a file connection, you’ll see the current (and now broken) file path. Click the Browse button next to the file path. A file explorer window will open. Navigate to the new location of your file, select it, and click Open.
- Confirm and Apply: You'll see the file path in the dialog box update to the new location. Click OK. Power Query will try to refresh the preview with the new location. If everything looks good, click the Close & Apply button in the top-left corner of the "Home" ribbon.
That’s it! Your report is now pointing to the correct file. If you have multiple queries pointing to different files that all moved, you will need to repeat this process for each one.
Method 2: The Pro Method Using Parameters (Better for Multiple Files or Future Changes)
Manually editing the source path is fine for one file, but what if you have ten Excel files all sourcing from the same folder that just moved? Or what if you know you’ll need to frequently switch between a test server and a production server? That's where parameters become incredibly powerful.
A parameter lets you store a piece of information, like a folder path or a server name, in one central place. Then, you can reference that parameter in all your queries. If the path changes, you only need to update the parameter, and all linked queries update automatically.
Step 1: Create the Parameter
- Open Power Query Editor: Just like before, open your report and go to Transform data.
- Create a New Parameter: In the Power Query Editor's "Home" ribbon, click Manage Parameters and select New Parameter from the dropdown.
- Configure the Parameter: A new window will appear. Fill it out as follows:
Step 2: Connect Your Queries to the Parameter
- Go to the Advanced Editor: Select the query you want to update. Instead of clicking the gear icon, click on Advanced Editor in the "Home" ribbon. This shows you the M code that Power Query is writing behind the scenes. It might look intimidating, but we're only making one small change.
- Find the Source Line: Look for the first line of code, which will likely start with
let Source = .... You'll see the full file path hard-coded in it, something like this:
let
Source = Excel.Workbook(File.Contents("C:\Users\OldPath\Downloads\ReportData.xlsx"), null, true)
in
Source- Modify the M Code: We need to replace that hard-coded path with a combination of our shiny new parameter and the file name. Change the line to this:
let
Source = Excel.Workbook(File.Contents(pFolderPath & "ReportData.xlsx"), null, true)
in
SourceThe ampersand (&) is used to combine the text from our pFolderPath parameter with the file name "ReportData.xlsx". This dynamically builds the full path.
4. Click Done and Apply: After editing the code, click Done. As long as the path in your parameter is correct and the file exists, the data preview will load. Now click Close & Apply.
Repeat step 2 for any other queries drawing from that folder. Now, the next time your boss decides to rename the primary data folder, you won't break a sweat. You'll just go to Manage Parameters, update the pFolderPath value, hit refresh, and everything will work instantly.
How to Change Database Connections
The process for changing databases (like from a test SQL server to a production server) is similar to the direct method.
- In Power Query, select your database query.
- Click the gear icon next to the Source step.
- A dialog box will pop up asking for the Server and Database names.
- Simply update the Server field from your old server name to your new server name (e.g., from
DEV-SQL01\INSTANCEtoPROD-SQL03\INSTANCE). - Click OK.
Power BI will likely prompt you for credentials since it's a new source. Enter your credentials, connect, and click Close & Apply. You can absolutely use parameters for server and database names too, which is highly recommended for managing different environments.
Troubleshooting Common Errors
- "We couldn't authenticate with the credentials provided." This means you need to update your permissions for the new source. In Power BI Desktop, go to File > Options and settings > Data source settings. Find the new data source in the list, click it, and then click "Clear Permissions," followed by "Edit Permissions" to re-enter your new credentials.
- "Expression.Error: The key didn't match any rows in the table." This frustrating error usually pops up right after you successfully change the source path. It means that while the file was found, something inside it is different. Most often, the worksheet name or table name has changed. Check the "Navigation" step in your Applied Steps to see what name it's looking for, and ensure it matches the new source file exactly.
Final Thoughts
Learning how to efficiently change a data source path is essential for keeping your Power BI reports durable and easy to maintain. Using the direct method works for quick fixes, but investing a few extra minutes to set up parameters for your folder paths and server names will save you hours of repetitive work down the road.
While managing local files and databases is a core skill, we know the modern data struggle often involves dozens of cloud applications that don't have simple file paths. We created Graphed to solve this bigger integration challenge. Instead of worrying about API keys and connection strings for your marketing and sales platforms like Google Analytics, Shopify, or Salesforce, you just connect your sources once. From there, you can ask in plain English to build real-time dashboards that show you the complete picture, without ever needing to worry about updating a broken link again.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.