Get our FREE VBA eBook of the 30 most useful Excel VBA macros.

Automate Excel so that you can save time and stop doing the jobs a trained monkey could do.

Claim your free eBook

Get data from OneDrive or SharePoint with Power Query

Power Query - Connect to SharePoint and OneDrive - Featured Image

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.

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.

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:

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.

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.


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:

Headshot Round

About the author

Hey, I’m Mark, and I run Excel Off The Grid.

My parents tell me that at the age of 7 I declared I was going to become a qualified accountant. I was either psychic or had no imagination, as that is exactly what happened. However, it wasn't until I was 35 that my journey really began.

In 2015, I started a new job, for which I was regularly working after 10pm. As a result, I rarely saw my children during the week. So, I started searching for the secrets to automating Excel. I discovered that by building a small number of simple tools, I could combine them together in different ways to automate nearly all my regular tasks. This meant I could work less hours (and I got pay raises!). Today, I teach these techniques to other professionals in our training program so they too can spend less time at work (and more time with their children and doing the things they love).

Do you need help adapting this post to your needs?

I'm guessing the examples in this post don't exactly match your situation. We all use Excel differently, so it's impossible to write a post that will meet everybody's needs. By taking the time to understand the techniques and principles in this post (and elsewhere on this site), you should be able to adapt it to your needs.

But, if you're still struggling you should:

  1. Read other blogs, or watch YouTube videos on the same topic. You will benefit much more by discovering your own solutions.
  2. Ask the 'Excel Ninja' in your office. It's amazing what things other people know.
  3. Ask a question in a forum like Mr Excel, or the Microsoft Answers Community. Remember, the people on these forums are generally giving their time for free. So take care to craft your question, make sure it's clear and concise.  List all the things you've tried, and provide screenshots, code segments and example workbooks.
  4. Use Excel Rescue, who are my consultancy partner. They help by providing solutions to smaller Excel problems.

What next?
Don't go yet, there is plenty more to learn on Excel Off The Grid.  Check out the latest posts:

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

  1. Don Anderson says:

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *