SharePoint is becoming a common data source for many organizations. With the increase of users on Microsoft 365 licenses, I think we can assume this will continue to grow. Teams, OneDrive, and Lists are all built on the SharePoint platform; therefore, it is easy to interact with SharePoint without knowing it. Given this increase, I thought we should look at how to get data from a SharePoint List using Power Query.
Note: In this post, we are looking at using SharePoint online. We are not looking at on-premise installations, but many principles will be the same.
Watch the video
Getting the SharePoint site URL
The first part of connecting to a SharePoint List is finding the URL. Unfortunately, it’s not as simple as just copying the URL from the address bar.
In the image above, I have a SharePoint list. The URL is:
However, we don’t want the full URL of the list. We just need the URL of the site. This includes up to and including the text after the word sites/.
Copy this part of the text.
Get the SharePoint list into Power Query
Now let’s head over to Excel.
There are two SharePoint List connectors, SharePoint List and SharePoint Online List. The differences between the two connectors will become clear in the next section.
For now, pick one; enter the site URL from above, then click OK.
Connects to SharePoint On-Premise and Online.
Click Data > Get Data > From Other Sources > SharePoint List
SharePoint Online List
Connects to SharePoint Online only.
Click Data > Get Data > From Online Services > SharePoint Online List
Selecting Implementation 2.0 enables us to retrieve all the columns from the list, or only those in the default view.
The Navigator window opens all the elements related to the SharePoint site. Select the site to load into Power Query, then click Transform Data.
Power Query displays the list in the Preview Window.
What data is available?
Depending on the connector selected, we see different data views:
SharePoint Online List
If you selected SharePoint Online List, you see different columns depending on the View Mode option chosen in the connector.
- Default: Only the data in the default view, plus an ID column
- All: All the data in the List, plus additional fields for the creator, modifier, attachments, version numbers, etc.
We can switch between views by editing the M code of the Source step. In the ViewMode parameter, enter the text “All” or “Default”, as shown in the example below.
= SharePoint.Tables("https://exceloffthegrid.sharepoint.com/sites/SharePointExample/", [Implementation="2.0", ViewMode="All"])
If we selected the SharePoint List, there might be more columns than you were expecting.
These additional columns give us access to the metadata about each record. For example, selecting a value in the Editor field displays the details about the last person to change the value (that might be useful at some point).
We can simply select the fields we wish to keep and click Home > Remove Columns > Remove Other Columns.
The M code in the Source step for this connector is as follows. Therefore, if we wanted, we could switch to the SharePoint Online List by changing the query parameters to those shown in the SharePoint Online List section above.
= SharePoint.Tables("https://exceloffthegrid.sharepoint.com/sites/SharePointExample/", [ApiVersion = 15])
Loading the data
In Power Query, Click Home > Close & Load To…
This leads to the Import Data dialog window. From here, you can decide where to put the data.
Loading into an Excel Table? Do we need Power Query?
If we are loading the data into an Excel Table without any other transformations, an alternative is a .iqy file.
In SharePoint, click Export > Export to Excel.
This downloads a file called query.iqy. Double-click the file to open it in Excel; this creates a workbook containing a Table with a live connection back to the SharePoint list.
To refresh the Table, click Data > Refresh.
However, if you need to do anything else with the data, then Power Query is the best option.
With the increased usage of SharePoint (including Teams, OneDrive, and Lists), it is becoming a more common source for data storage. In this post, we’ve seen how to easily connect to this data and load it into Excel using Power Query.
- Get data from OneDrive or SharePoint with Power Query
- Get data from OneDrive Personal files with Power Query
- How to get data into Power Query – 5 common data sources
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:
- Read other blogs, or watch YouTube videos on the same topic. You will benefit much more by discovering your own solutions.
- Ask the 'Excel Ninja' in your office. It's amazing what things other people know.
- 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.
- Use Excel Rescue, who are my consultancy partner. They help by providing solutions to smaller Excel problems.
Don't go yet, there is plenty more to learn on Excel Off The Grid. Check out the latest posts: