Skip to main content
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
negbc
Helper II
Helper II

Setting Up Dynamic Source File Name

I'm looking to create a source file path to which the file name can change dynamically by date. I will have a daily extract to a folder, with the same naming convention "Name.YYMMDD" with that date being the extract date. In power query I want to connect, for example, to the file the is -7 days from today, or -14 days from today. Is there a way to format the file path so it changes everyday when the report freshes to file name that has the date corresponding to the date -7 days from the current day?

5 REPLIES 5
dufoq3
Community Champion
Community Champion

Hi @negbc,

 

dufoq3_0-1715015658627.png

= "Name." & Date.ToText(Date.AddDays(Date.From(DateTime.FixedLocalNow()), -7), [Format="yyyyMMdd"])

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Would this replace the entire source code? or would I still need some of the elements that as shown below and replace the file path with the code you provided?

 

negbc_0-1715171924527.png

 

Hello,

Were you able to have a solution on your question?
I am looking for the same code, and I can't find how to include the code mentionned in the one I am using.
I need to include : 

= "Name." & Date.ToText(Date.AddDays(Date.From(DateTime.FixedLocalNow()), -7), [Format="yyyyMMdd"])


in 

= Csv.Document(File.Contents("C:\Users\NAME\Desktop\DATABASE\DATA123\123OTB.110924.txt"),[Delimiter=" ", Columns=19, Encoding=1200, QuoteStyle=QuoteStyle.None])

The  code above is the source code I have when I go manually looking for the file, so I guesses I just needed to replace the name of the file by the code suggested? But so far it didn't work I have the below error.

Expression.SyntaxError : Jeton Comma

Any idea what is wrong?

Thanks a lot !

There wasn't an exact solution as the dynamic source code doesn't work with automatic refreshes, so wouldn't work for my solution. However, you could still try with a single source.

 

Create a variable first for the date, last week for example:

LW = Date.ToText(Date.AddDays(Date.From(DateTime.LocalNow()),-7),"MMddyy")

 

Then in your source code, enter the variable, concatenated to the file name.

= Csv.Document(File.Contents("C:\Users\NAME\Desktop\DATABASE\DATA123\"123OTB."& LW &".txt"),[Delimiter=" ", Columns=19, Encoding=1200, QuoteStyle=QuoteStyle.None])

 

I ended up connecting an entire folder and then selected the files I needed used this dynamic code, that way the refresh is the entire folder instead of a single file.

dufoq3
Community Champion
Community Champion

Hi @abc44 & @negbc. It is possible to do it the way above, but I would use Folder.Files and filter newest file.

 

1.) Use Folder as source

dufoq3_0-1726123765246.png

 

2.) Click Transform Data

 

3.) Sort by Date Crated (descending order) if necessary

 

4.) Click at 1st Binary in [Content] column

dufoq3_4-1726124259823.png

 

5.) Edit Navigation step and replace selected with 0 so the code for this step will be:

 

= Source{0}[Content]

 

dufoq3_3-1726124222924.png

This will choose 1st file dynamicaly.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.