Forum Discussion
Ocasio27
May 22, 2020Iron Contributor
Change from absolute to relative path in Power query
I often have to change the actual path of my workbook, or share it, so I want to change the query location in a way that as long as both files are in the same directory, they work Source = Excel....
SergeiBaklan
May 22, 2020MVP
Please check this thread https://techcommunity.microsoft.com/t5/excel/power-query-source-from-relative-paths/m-p/206150
- Ocasio27May 22, 2020Iron Contributor
I was trying that but I get an error
let
WBPath = Excel.CurrentWorkbook(){[Name="WBPath"]}[Content]{0}[Column1],
FullPathToFile1 = Table1 "filename.xlsx",
Source = Excel.Workbook(File.Contents(FullPathToFile1), null, true),Expression.SyntaxError: Token Comma expected.
- SergeiBaklanMay 22, 2020MVP
I didn't catch what the Table 1 is in your script. Let me illustrate on my sample.
Here
we have the cell named filepathCELL which returns full path of the current file. With that entire script could be
let myAnotherFile = "dataFile.xlsx", thisFilePath = Excel.CurrentWorkbook(){[Name="filepathCELL"]}[Content]{0}[Column1], onlyPath= Text.Split(thisFilePath,"["){0}, fullpathAnotherFile = onlyPath & myAnotherFile, Source = Excel.Workbook(File.Contents(fullpathAnotherFile)) in Source
Please note that works only on local folders, with folders synced with Onedrive/Sharepoint CELL() returns web-like file path (http://...)
- RobDerbyJan 31, 2021Copper ContributorIs there any way to make this work with one drive synced folders (like Desktop)? This works fine if I move the files to an external drive, but my File Path returns a URL when running from my desktop.