Forum Discussion
gancw1
4 years agoResolver II
Load most recent file from SharePoint folder
I would like to load the most recent CSV file from a SharePoint folder. i tried using the method below but it seems the file and path is hardcoded. let Source = SharePoint.Files("https://musux...
- 4 years ago
Remember you can address rows and columns in Power Query. Here is an example to open the newest Excel file. You can adjust it for csv. Note there is no need for the "keep only first row" transform.
let Source = SharePoint.Files("https://your.sharepoint.com/sites/yoursite", [ApiVersion = 15]), #"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".xlsx")), #"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"Date modified", Order.Descending}}), #"First File" = #"Sorted Rows"{0}[Content], #"Imported Excel Workbook" = Excel.Workbook(#"First File") in #"Imported Excel Workbook"
lbendlin
4 years agoSuper User
Remember you can address rows and columns in Power Query. Here is an example to open the newest Excel file. You can adjust it for csv. Note there is no need for the "keep only first row" transform.
let
Source = SharePoint.Files("https://your.sharepoint.com/sites/yoursite", [ApiVersion = 15]),
#"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".xlsx")),
#"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"Date modified", Order.Descending}}),
#"First File" = #"Sorted Rows"{0}[Content],
#"Imported Excel Workbook" = Excel.Workbook(#"First File")
in
#"Imported Excel Workbook"
gancw1
4 years agoResolver II
Thanks. I am new to M and did not know about the syntax for addressing row and column!
How do i store the file name in another table so that I can display the name of the file ?