Forum Discussion
Need to load all Excel files in a given OneDrive folder...
Using Power BI Desktop, I can readily load to my data model all the Excel files in a given folder. Works great. However, I can't figure out how to accomplish the same if the files are in a OneDrive for Business folder. I can load a single Excel file from OneDrive when I fully specify the URL in the Get Data from Web function - but how do you get a list of files found in a OneDrive folder?
11 Replies
- yossifischAdvocate I
For OneDrive for Business or SharePoint, you can edit the query from SharePoint.Files to SharePoint.Contents. This will allow you to navigate to a specific folder by clicking the folder name to expand the table (which is the folder's contents) rather than filtering for it as I suggested in my previous comment. You can then use the Combine Files button to merge the files using the automated custom function just like you would when connecting to a local folder.
This solution is really fast. I found out about this from commenter Shawn on Excelerator BI: https://exceleratorbi.com.au/consolidate-multiple-excel-files-in-sharepoint-using-powerquery/#comment-287.- AnonymousNot applicable
Not sure how this scales, both the file size and number of files I am using is pretty limited, but this works for me:
- In Power BI Desktop go to Edit Queries and select the Source step. The function should be looking like SharePoint.Files("<your_url>", [ApiVersion = <version>])
- Use this function as first parameter to the Table.FindText function, and use the second parameter for your file/folder pattern. So the new function in the Source step should looks something like Table.FindText(SharePoint.Files("<your_url>", [ApiVersion = <version>]), "<your_filter>")
- When adding a new source (e.g. if you want some other files with a different data model in a separate folder to be included), make sure you Transform Data first if needed, as you need to use the two steps above to filter out the correct files/folders. After that, the two queries will have their own helper queries and can have their own file transformations.
- Greg_DecklerCommunity Champion
Other than syncing your OneDrive folders locally, I can't think of a way to do this, I don't think you can pass a Folder URL to the "Folder" data source.
- bpearceAdvocate I
"Other than syncing your OneDrive folders locally..."
Sorry, I should have further specified it is critical that when published, Power BI must be able to refresh the data model. Thus specifying a local folder as a data source will not work.
Any other suggestions?
- AntonRozensonRegular Visitor
Solved:
1. Get a list of files (URLs) via = SharePoint.Tables("https://SomeOrgName.sharepoint.com/personal/Email_with_undescores/", [ApiVersion = 15])
2. Expand Documents "Table"
3. Expand "File.LinkingUrl" and split by "?" to get a clean URL
4. Do filter the desired folder (via URL or Folder.Name or other attribution)
5. Add a Custom Column = Excel.Workbook(Web.Contents([File.LinkingUrl))