Get data from OneDrive or SharePoint with Power Query

In Power Query, when we connect to a local file, it’s reasonably obvious how we do that; it’s built directly into the UI. We just need to navigate to the location… Bam. Done! However, what if we want Power Query to get data from OneDrive or SharePoint? How do we do that? It’s not obvious. Actually, sometimes what seems like the answer can lead us down the wrong “file” path (oh, sorry, that was a terrible Dad joke).

As more companies use online storage locations such as OneDrive and SharePoint, the more relevant the data connectors to these sources become.

If you are looking to get data from OneDrive personal, check out this post: Get data from OneDrive Personal files with Power Query

So, in this post, I want to show you how to connect to OneDrive or SharePoint with Power Query.

Table of Contents

Watch the video


Watch the video on YouTube.

Find the URL

OneDrive and SharePoint both use web connections, so the first thing we need to do is find the URL of the file. The problem is that it’s harder to find the URL than you might think.

If you open the file online and look at the URL in the address bar, that’s got to be it, right… wrong! This won’t work.

URL in address bar - does not connect

Initially, it will ask you to sign in to your Microsoft account. It will appear to be connecting, and then… ha, ha, fooled you! You’ll get the error message below.

Unable to Connect error message

OK, let’s try another method. If you copy the share link for the file, that’s got to work, right? Nope!

Copy link is the wrong URL

The share copy URL will also return the “Unable to connect” error.

So, where are the URLs you need? Microsoft has hidden them away; they are like little Easter Eggs for us to find.

Option #1

Now let’s look at the first valid option:

  • Navigate to the file in OneDrive or SharePoint.
  • Click on the (i) information button in the top right.
  • With the information pane open, scroll down until you find the Path (it is there, though it might not be visible on the screen initially, keep scrolling).
  • Click the Copy button next to the word “Path”.
Copy URL from Path

You have now copied the URL to the clipboard.

Option #2

If the file is already open in Excel, we can get the path directly inside Excel.

  • Click File > Info
  • Click the Copy Path button at the top
Get URL from open workbook

You have now copied the URL to the clipboard.

Connect to the file in Power Query

Now we have the URL, we can use a web connector in Power Query. Click Data > From Web (or the alternative is Data > Get Data > From Other Sources > From Web).

Paste the URL into the URL box.

If you used Option #2, the URL will have ?web=1 at the end. You don’t need this, so just delete those characters from the end of the URL. Option #1 doesn’t have this additional piece of text, so we won’t need to make this change.

Click OK.

Get SharePoint data from URL

You may need to sign in using your organizational account. You should only need to do this once.

Sign-in to connect

Ta-dah! You are now connected to the file on OneDrive or SharePoint. Before you ask, yes, you can create a cell parameter for this. Check out this post to find out how: https://exceloffthegrid.com/power-query-source-cell-value/

Connect to a folder instead of a file?

If you want to connect to a folder rather than an individual file, we already have the information we need.

By looking at the URL for a file, we can identify the folder path.

https://exceloffthegrid.sharepoint.com/sites/ExampleSite/Shared%20Documents/myFile.xlsx

The bold section is the part we need; the end section can be removed.

To connect to a SharePoint folder in Power Query, go to Data > Get Data > From File > From SharePoint Folder.

Enter the folder path from above and click OK.

Power Query connect to SharePoint folder

Ta-dah!! You can now connect to an entire folder in SharePoint or OneDrive.

Conclusion

Connecting to files and folders stored on OneDrive or SharePoint is possible. It may appear that Microsoft have hidden away this information. But now you know where to look; it should all be straightforward.

Related Posts:


Discover how you can automate your work with our Excel courses and tools.

Excel Academy

Excel Academy
The complete program for saving time by automating Excel.

Excel Automation Secrets

Excel Automation Secrets
Discover the 7-step framework for automating Excel.

Office Scripts Course

Office Scripts: Automate Excel Everywhere
Start using Office Scripts and Power Automate to automate Excel in new ways.

1 thought on “Get data from OneDrive or SharePoint with Power Query”

  1. Mark,
    We recently moved from a SharePoint on-prem to SharePoint Online and now I’m attempting to change the Power Query Source folder from a mapped drive to the SharePoint on-prem to the SharePoint Online folder. I can connect to the first part of the https;//blah/blah, but I need to get 3 levels deeper, ie, https;//blah/blah/blah/blah/blah/. When I do connect to https;//blah/blah and select Connect, the Navigator window shows me a bunch of tables, so I select one and load….still not getting where I need to be. Any ideas?

    Reply

Leave a Comment