Forum Discussion
ChristopherDuncan
Jul 19, 2021Copper Contributor
Power Query Relative Path for OneDrive and Other Users
Let me start by saying that I have read the posts about converting from an Absolute path to a Relative path in PowerQuery (primarily https://techcommunity.microsoft.com/t5/excel/power-query-source-fr...
- 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.
ChristopherDuncan
Jul 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),
johnnydevv
Apr 28, 2022Copper Contributor
ChristopherDuncan @sergei_baklan
What if I am trying to reference a folder and not a file (as in excel workbook). Will I still use Web.Contents & File.Contents?
- SergeiBaklanApr 28, 2022MVP
No, that's From (Sharepoint) Folder connector
- johnnydevvApr 28, 2022Copper Contributor
I don't really understand what you mean. Please can you show me the code syntax for it?