dynamic source

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
755
Office Version
  1. 365
  2. 2010
so my source file points to a dated folder and file name

eg. c:\daily files\feb\09\sample09.xlsx

so ofc the next day it'll be different....if i refresh the query, it wont work because it's still pointing to feb 9

is there a dynamic way to refresh this? or is manually editing the code in powery query the only way? not ideal imo
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I looked into this issue recently and found this idea useful:
 
Upvote 0
i feel like they should have made this a lot easier to do....i mean, having the file name change daily by date is pretty common for office files
 
Upvote 0
I don't know if the video has the same method but it is always good to keep the written solution in this page for members who'd prefer to read/copy/paste and to help visitors using search feature.

You can do that with a small edit in the M code. Open the Advanced Editor. You will see something like this at the beginning that connects to the workbook:

Power Query:
    Source = Excel.Workbook(File.Contents("c:\daily files\feb\09\sample09.xlsx"), null, true),

What we can do is changing feb, and 09 with the current day's month and day values, and it can be done as shown below:

Power Query:
    strMonth = Text.Lower(Date.ToText(Date.From(DateTime.LocalNow()), [Format="MMM"])), // This is "feb" for February
    strDay = Date.ToText(Date.From(DateTime.LocalNow()), [Format="dd"]), // This is "09" for February 9th
    strFileName = "sample" & strDay & ".xlsx", // This is sample09.xlsx for February 9th
    strPath = "C:\daily files\" & strMonth & "\" & strDay & "\" & strFileName, // Finally, this is the concatenated string as dynamic path
    Source = Excel.Workbook(File.Contents(strPath), null, true),
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top