Load Files from a SharePoint Folder in Power Query M

Connects to a SharePoint document library and combines every file in a folder, the same way Folder.Files works locally.

File HandlingAdvancedsharepointfoldercombine files

Power Query M code

let
    Source = SharePoint.Files("https://yourcompany.sharepoint.com/sites/YourSite", [ApiVersion = 15]),
    FilteredFolder = Table.SelectRows(Source, each Text.Contains([Folder Path], "/Shared Documents/YourFolder")),
    AddedData = Table.AddColumn(FilteredFolder, "Data", each Excel.Workbook([Content], true))
in
    AddedData

Notes

Replace the site URL and folder path filter with your own; sign in with an account that has access to the site when prompted.

Requirements

How to use this snippet

  1. In Power BI Desktop, choose Transform data to open Power Query, then open the Advanced Editor on a query (or start from a blank query).
  2. Paste the snippet and replace the placeholder names (tables, columns, file paths) with your own. Check the requirements above first.
  3. Run it through the Power Query M Formatter to tidy the layout.

Related Power Query M snippets

More Power Query M resources

Browse all 145 snippets in the Power Query M Code Snippets, or search the library for something similar to Load Files from a SharePoint Folder.