I have a query where the Source is a particular workbook
Source = Excel.Workbook(File.Contents("C:UserscharlDropboxLS DevWholesaleWholesaleOrderForm_Template.xlsm"), null, true),
As this file is to be distributed to wholesale customers I need the path to the file to be dynamic. I have this in a cell in a workbook which will also be distributed
=LEFT(CELL("filename",A4),FIND("[",CELL("filename",A4))-1)&"WholesaleOrderForm_Template.xlsm"
which returns the file path & file name correctly and which I used to hard code the file path into Source as above. This works fine but is not dynamic.
I have tried making the file path & file name from that formula as a List in the query but can't get the hard coded File path to be replaced with the List.
Using Windows 11 and Office 365.
Any help greatly appreciated.
Edit:
I use similar to get the latest CSV file from a folder, which works perfectly
let
MyFolder=Excel.CurrentWorkbook(){[Name="CatFldr"]}[Content][Column1]{0},
Source = Folder.Files(MyFolder),
#"Sorted Rows" = Table.Sort(Source,{{"Date created", Order.Descending}}),
#"Kept First Rows" = Table.FirstN(#"Sorted Rows",1),
GetTables = Table.AddColumn(#"Kept First Rows", "GetTbl", each Table.PromoteHeaders(Csv.Document([Content],
So I tried
let
MyFile=Excel.CurrentWorkbook(){[Name="OrderForm"]}[Content][Column1]{0},
Source = Excel.Workbook(File.Contents(MyFile, null, true),
But get an error "Token "," Expected"
CatFldr & OrderForm are Named Ranges holding the formulae to get the required paths.
I got it sorted, couldn't see the wood for the trees! I had left off the closing bracket after MyFile.
let
MyFile=Excel.CurrentWorkbook(){[Name="OrderForm"]}[Content][Column1]{0},
Source = Excel.Workbook(File.Contents(MyFile), null, true),
The error "Token "," Expected" is confusing as I was looking for a missing comma.
Hi Charles:
Try the following formula in your workbook to acquire the path:
=LEFT(CELL("filename"),FIND("[",CELL("filename"))-1)
Then connect the cell containing the dynamic path to Power Query.
Drill Down on the path to create a path parameter
Rename the Query to "MyPath" or something descriptive
Replace the path in your Source step with your new parameter:
= Excel.Workbook(File.Contents(MyPath & "Data.xlsx"), null, true)
Hope this helps
Rob