Forum Discussion
Power Query Relative Path for OneDrive and Other Users
- Jul 19, 2021
That could be like
Source = if Text.Start(filepath,5) = "https" then Web.Contents(...) else Csv.Document(...),
but you shall to clean filepath before (remove sheet name and brackets). You may do in sheet by formula or in Power Query by another if then else. Hope it's possible to find ready to use pattern for both.
That's only parse CELL("filename"). If it starts from "https://..." remove sheet name from the end, substitute [] around filename on nothing and connect like
Source = Excel.Workbook(Web.Contents("https://tenant.sharepoint.com/teams/site/docs/file.xlsx"), null, true),
...
If not, use connection as in mentioned by you thread.
- SergeiBaklanJul 19, 2021MVP
That could be like
Source = if Text.Start(filepath,5) = "https" then Web.Contents(...) else Csv.Document(...),
but you shall to clean filepath before (remove sheet name and brackets). You may do in sheet by formula or in Power Query by another if then else. Hope it's possible to find ready to use pattern for both.
- DarifmohammedhotmailFeb 06, 2024Copper ContributorThank you very much.
- ChristopherDuncanJul 20, 2021Copper Contributor
SergeiBaklan Thank You!
For anyone else who comes along, here is what worked for me to get a Power Query Relative Path that works for both file paths and One Drive addresses.
- Created a Worksheet titled Setup with this formula in cell B4:
=LEFT(CELL("filename",A1), FIND("[", CELL("filename",A1))-1) - Created a Defined Name for B4 and called it FilePath
- Hid the Setup Worksheet
- Clicked in my previously linked data I imported with Power Query.
- Clicked the Query tab in the Ribbon
- Clicked Edit on the Query tab
- Clicked Advanced Editor on the Home tab of Power Query Editor
- Changed the source line of my code to read as follows:
FilePath = Excel.CurrentWorkbook(){[Name="FilePath"]}[Content]{0}[Column1],
FullPathToFile1 = FilePath & "export-information\orders.xlsx",
Source = if Text.Start(FullPathToFile1, 4) = "http"
then Excel.Workbook(Web.Contents(FullPathToFile1), null, true)
else Excel.Workbook(File.Contents(FullPathToFile1), null, true),
- NG_CAXJun 02, 2023Copper Contributor
I am trying to pull in files from my company sharepoint environment and have followed the code to the T
Here it is
letFilePath=Excel.CurrentWorkbook(){[Name="FilePath"]}[Content]{0}[Column1],FullPathToFile1 = FilePath & "Outline_WAG_WITHOUT_CONNECTION.xlsx",Source = if Text.Start(FullPathToFile1,4) = "http"then Excel.Workbook(Web.Contents(FullPathToFile1),null,true)else Excel.Workbook(File.Contents(FullPathToFile1),null,true),But I can't seem to pull the data in. Is there an way you can still help with this?Best,Neha
- Created a Worksheet titled Setup with this formula in cell B4: