Forum Discussion

reggierevello's avatar
reggierevello
Frequent Visitor
9 years ago
Solved

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

  • 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. :smileyhappy:

     

    Regards

1 Reply

  • v-ljerr-msft's avatar
    v-ljerr-msft
    Icon for Microsoft Employee rankMicrosoft 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. :smileyhappy:

     

    Regards