To get data from a SharePoint folder in Power Query, use the Get Data > From File > From SharePoint Folder connector and enter the root URL of your SharePoint site. This process allows you to combine multiple files with the same schema (such as monthly CSV or Excel reports) into a single table automatically, ensuring that any new files added to the folder in the future are included upon refreshing the data.

What You'll Need

  • An active Microsoft 365 account with access to the SharePoint site.
  • The URL of the SharePoint site (specifically the root site address, not the link to a specific folder or file).
  • Microsoft Excel or Power BI Desktop installed on your machine.
  • Files stored in the SharePoint folder that share a consistent structure (same columns and headers) if you intend to combine them.

Step-by-Step

  1. Copy the SharePoint Site URL: Navigate to your SharePoint site in a web browser. Look at the address bar. You need the root URL of the site, not the path to the specific document library or folder. For example, if your URL is https://company.sharepoint.com/sites/FinanceDepartment/Shared Documents/Reports, you only need https://company.sharepoint.com/sites/FinanceDepartment. Copy this root address.
  2. Launch the Connector: Open Excel or Power BI Desktop. Go to the Data tab on the ribbon. Select Get Data > From File > From SharePoint Folder. (Note: Menu labels may vary slightly depending on your software version or region).
  3. Enter the Site URL: A dialog box will appear asking for the Site URL. Paste the root URL you copied in Step 1 into the text field. Click OK.
  4. Authenticate the Connection: If this is your first time connecting to this site, you will be prompted to sign in. Select Microsoft Account from the left-hand sidebar. Click Sign in, enter your organizational credentials, and once the account is verified, click Connect.
  5. Preview the File List: Power Query will now display a preview table listing every single file present in that SharePoint site's document libraries. Do not click Combine yet, as this will attempt to merge every file on the site. Instead, click Transform Data.
  6. Filter for Your Specific Folder: In the Power Query Editor, look for the Folder Path column. Click the filter arrow in the column header, go to Text Filters > Contains, and type a unique part of the folder path where your target files are stored. This ensures you are only targeting the specific sub-folder you need.
  7. Filter by File Extension: To avoid errors caused by hidden system files or temporary files, find the Extension column. Filter this to only include the file types you need (e.g., .xlsx or .csv).
  8. Combine the Files: Once you have filtered the list down to only the files you want to merge, locate the Content column (usually the first column). Click the Combine Files icon (two downward-pointing arrows) in the column header.
  9. Select the Object to Extract: A Combine Files dialog will appear. Power Query uses the first file in the folder as a "Sample File." If you are importing Excel workbooks, select the specific sheet or table name from the list on the left. Click OK.
  10. Finalize and Load: Power Query will now automatically create a series of helper queries to extract the data from each file and append them together. Review the resulting table to ensure the columns are correct. Once satisfied, click Close & Apply (Power BI) or Close & Load (Excel).

Common Mistakes

The most frequent error occurs during the URL entry phase. Users often paste the full path to the folder (e.g., .../Shared Documents/2023/Invoices). Power Query will return an error stating that the URL is invalid because the SharePoint Folder connector expects the Site URL, not the Folder URL. Always stop the URL at the site name.

Another common mistake is skipping the filtering step. Because the connector scans the entire site, clicking "Combine" immediately will result in Power Query trying to merge every PDF, image, and spreadsheet on the site into one table. This usually leads to a "DataFormat.Error" because the files have different structures. Always use the Transform Data option to filter the Folder Path and Extension columns first.

Users also frequently forget to check for "ghost files." If a user has an Excel file open in the SharePoint folder while the query is running, SharePoint often creates a temporary owner file (starting with ~$). If these are not filtered out using a Text Filter > Does Not Begin With on the Name column, the query may fail during the combine process.

Tips

To make your query more robust, use Parameterization for the Site URL. Instead of hard-coding the URL into the source step, create a Power Query Parameter. This allows you to switch between a "Development" SharePoint site and a "Production" site without editing the M-code in every single query.

If you are dealing with a massive number of files, the initial preview can be slow. To optimize performance, ensure that you filter the Folder Path as the very first step after the Source step. This reduces the amount of data Power Query has to hold in memory before it begins the combination process.

When combining files, ensure that the column headers in every file are identical in spelling and casing. Power Query is case-sensitive; "Invoice Date" and "invoice date" will be treated as two separate columns, resulting in a fragmented table with many null values.

Troubleshooting

If you receive an "Access Forbidden" or "403" error, the first step is to clear your permissions. In Excel, go to Data > Get Data > Data Source Settings. Find the SharePoint URL in the list, select it, and click Clear Permissions. Then, try the connection again, ensuring you select Microsoft Account rather than Anonymous or Windows authentication.

If the "Combine Files" step fails with a "Column not found" error, it means one of the files in your folder does not match the schema of the Sample File. To fix this, go back to the Transform Data window and check the filtered list of files. Ensure no unexpected files have been added to the folder. You can also change the Sample File in the "Sample File" query folder in the left pane to a more representative document.

If the data is not refreshing when new files are added, check the SharePoint folder permissions. The account used to authenticate the Power Query connection must have at least "Read" access to the folder. If the files are uploaded via an automated process, ensure they are fully checked in and not marked as "checked out" by another user, as checked-out files may not be visible to the connector.

Frequently Asked Questions

Can I connect to a specific sub-folder only?

No, the connector requires the root site URL. However, you can isolate a specific sub-folder by using the Transform Data button and filtering the Folder Path column to include only that specific directory.

Do I need to rename files for this to work?

No, the files do not need specific names. As long as they are in the correct folder and share the same internal structure (columns and headers), Power Query will combine them regardless of their filenames.

Will this work with CSV files as well as Excel?

Yes, the SharePoint Folder connector works with any file type. When you click Combine Files, Power Query will detect the file extension and prompt you for the appropriate delimiter (for CSVs) or sheet name (for Excel).

What happens if I add a new column to the source files?

If you add a column to the files, you may need to update the "Sample File" query. Power Query bases the combined schema on the first file it sees; if new columns are added to subsequent files but not the sample file, those columns may be ignored.

Can I use this to merge files from different SharePoint sites?

Not with a single connector instance. Each SharePoint Folder query is tied to one root site URL. To merge data from different sites, create separate queries for each site and then use the Append Queries feature to join them into one master table.