The M Code Behind the Power Query M function SharePoint.Contents

To fully understand the SharePoint.Contents function, it is important to take a deeper look into the M code that powers this function. In this article, we will explore the M code behind the SharePoint.Contents function, as well as its various parameters and options.

Understanding the SharePoint.Contents Function

The SharePoint.Contents function is used to access data from SharePoint lists, folders, and files. It is part of the Power Query M language, which is used to extract and transform data from various sources. The function takes several parameters, including the URL of the SharePoint site, the relative URL of the file or folder, and the authentication method used to access the data.

The function returns a table containing the data from the specified SharePoint location. This table can then be further transformed and analyzed using Power Query’s other features.

The M Code Behind SharePoint.Contents

The M code behind the SharePoint.Contents function is responsible for accessing and retrieving the data from SharePoint. The code uses several built-in functions and operators to perform this task.

Here is an example of the M code used to retrieve data from a SharePoint list:


Source = SharePoint.Contents(“”, [ApiVersion = 15]),

List = Source{[Name=”TestList”]}[Items]



This code uses the SharePoint.Contents function to connect to the specified SharePoint site and retrieve data from the "TestList" list. The [ApiVersion = 15] parameter specifies the version of the SharePoint API to use.

The code then uses the curly brackets ({}) to specify the row or rows of data to retrieve from the list. In this case, we are retrieving all the items in the "TestList" list.

Parameters and Options

The SharePoint.Contents function takes several parameters and options that can be used to customize the data retrieval process.


The URL parameter specifies the URL of the SharePoint site to connect to. This parameter is required for the function to work.


The ApiVersion option specifies the version of the SharePoint API to use. The default value is 14, but you can specify a different value if needed.

Folder Path

The Folder Path option specifies the relative URL of the folder to retrieve data from. If this option is not specified, the function will retrieve data from the root of the site.


The Filter option specifies a filter to apply to the data retrieval process. This option can be used to retrieve specific items or files from a SharePoint list or library.


The Credentials option specifies the authentication method to use when connecting to SharePoint. This option can be set to "Windows", "Anonymous", or "Forms".

Best Practices

When using the SharePoint.Contents function in Power Query, there are a few best practices to keep in mind:

1. Use the latest version of the SharePoint API to ensure compatibility with the function.

2. Specify the exact folder or file path to retrieve data from to avoid unnecessary data retrieval and processing.

3. Use the Filter option to retrieve only the data you need, rather than retrieving all the data and then filtering it later.

By following these best practices, you can ensure that your data retrieval process is efficient and effective.

The SharePoint.Contents function is a powerful tool for retrieving data from SharePoint lists, folders, and files. By understanding the M code behind this function and its various parameters and options, you can customize the data retrieval process to meet your specific needs. When used in conjunction with other Power Query features, you can transform and analyze your SharePoint data to gain valuable insights and make informed decisions.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us


    Your Name (required)


    Email (required)


    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)