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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
reggierevello
Frequent Visitor

Import the newest excel file from SharePoint

HI, Do you know a way to access the lastest excel file uploaded to a Sharepoint folder?

 

I need to based my access in Upload latest date, not by name of the file.

 

Thanks

 

Reggie

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @reggierevello,

Based on my test, The M code below should work in this scenario. 

let
    Source = SharePoint.Files("https://mytenant.sharepoint.com/teams/abc", [ApiVersion = 15]),
    #"Sorted Rows" = Table.Sort(Source,{{"Name", Order.Descending}}),
    #"Kept First Rows" = Table.FirstN(#"Sorted Rows",1),
    #"Invoke Custom Function1" = Table.AddColumn(#"Kept First Rows", "Transform File from Query1", each #"Transform File from Query1"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File from Query1"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from Query1", Table.ColumnNames(#"Transform File from Query1"(#"Sample File"))),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Product", type text}, {"Category", type text}, {"Segment", type text}, {"ManufacturerID", Int64.Type}, {"Manufacturer", type text}})
in
    #"Changed Type"

In addition, here is a good article about loading the newest excel file from a Folder which is similar to loading from SharePoint Folder for your reference. Smiley Happy 



Above is a solution I mentioned in this similar thread. Smiley Happy

 

Regards

View solution in original post

1 REPLY 1
v-ljerr-msft
Employee
Employee

Hi @reggierevello,

Based on my test, The M code below should work in this scenario. 

let
    Source = SharePoint.Files("https://mytenant.sharepoint.com/teams/abc", [ApiVersion = 15]),
    #"Sorted Rows" = Table.Sort(Source,{{"Name", Order.Descending}}),
    #"Kept First Rows" = Table.FirstN(#"Sorted Rows",1),
    #"Invoke Custom Function1" = Table.AddColumn(#"Kept First Rows", "Transform File from Query1", each #"Transform File from Query1"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File from Query1"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from Query1", Table.ColumnNames(#"Transform File from Query1"(#"Sample File"))),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Product", type text}, {"Category", type text}, {"Segment", type text}, {"ManufacturerID", Int64.Type}, {"Manufacturer", type text}})
in
    #"Changed Type"

In addition, here is a good article about loading the newest excel file from a Folder which is similar to loading from SharePoint Folder for your reference. Smiley Happy 



Above is a solution I mentioned in this similar thread. Smiley Happy

 

Regards

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.