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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Super User
Super User

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors