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.Workbook(File.Contents("C:\Users\me\Documents\file.xlsx"), null, true),
I want that as long as file.xlsx is in the same directory as my workbook, it will find it
Source = Excel.Workbook(File.Contents("\file.xlsx"), null, true),
Ive try this but does not work
- Ocasio27Iron 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.
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://...)