Forum

Need File Path to b...
 
Notifications
Clear all

Need File Path to be Dynamic

3 Posts
2 Users
0 Reactions
491 Views
(@kjbox)
Posts: 69
Trusted Member
Topic starter
 

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.

 
Posted : 30/10/2024 7:40 pm
(@kjbox)
Posts: 69
Trusted Member
Topic starter
 

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.

 
Posted : 31/10/2024 1:43 am
(@northlandinc)
Posts: 1
New Member
 

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

 
Posted : 04/11/2024 6:02 pm
Share: