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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Get Data from Folder with Today's Date

Hi all,

 

I need PowerQuery to go every time and  search for a file that is stored in a folder with today's date.

 

Explanation:

 

Our raw data (the one we feed to PowerQuery) are stored to our local shared drive; this is an example of the path:

 

REPORTS [FOLDER]

----------30102019 [FOLDER]

               file1.csv

----------31102019 [FOLDER]

               file1.csv

 

As you can see,  every day the new report is stored in a folder with the same date of when the report is extracted.

 

  • The filename never changes.
  •  
  • The timestamp on the folder is when the folder itself was created.

 

How can I tell PowerQuery to go and look for the latest folder and pickup file1.csv?

 

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi luke_avalle, 

You could try below M code to see whether it work or not

let
    Source = Folder.Files("C:\Users\(username)\Documents\New folder"),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Folder Path] = "C:\Users\zoezhi\Documents\New folder\"&Date.ToText(DateTime.Date(DateTime.LocalNow()),"yyyyMMdd")&"\"))
in
    #"Filtered Rows"

 

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
cizzxr
New Member

Hi all, 

Just to add an extra bit of complexity onto this - how would I allow other users to refresh this power query?.

 

Let's say I have a sharepoint with the excel file in. Is it possible for others who have access to this sharepoint to go in and refresh this query so it pulls the most recent data, without them having to setup a new data source connection each time? 

dax
Community Support
Community Support

Hi luke_avalle, 

You could try below M code to see whether it work or not

let
    Source = Folder.Files("C:\Users\(username)\Documents\New folder"),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Folder Path] = "C:\Users\zoezhi\Documents\New folder\"&Date.ToText(DateTime.Date(DateTime.LocalNow()),"yyyyMMdd")&"\"))
in
    #"Filtered Rows"

 

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

delaclqm
Regular Visitor

@Anonymous I had something similar that I had to work with.  The solution I found was by using a the 

DateTime.LocalNow()

 function in Power Query. You can then extract the day, month, and year and create a string to match the format that you use in your file structure. To manipulate the date, you can use 

DateTime.ToText()

 function to format the date as you wish.

 

Hope that helps!

Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous ,
We need to get @KenPuls  who wrote an incredible book, M is for (DATA) MONKEY if he is available to comment.


If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors