Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

How can I pick the latest file with Power Query?

Hello

 

How can I pick the latest file from a list of sharepoint files in a folder using Power Query?

 

Thanks!

 

  • v-yingjl's avatar
    v-yingjl
    5 years ago

    Hi Anonymous ,

    The power query code is like this:

    let
        Source = SharePoint.Files("https://xxx.sharepoint.com/sites/xxx", [ApiVersion = 15]),
        #"Filtered Rows" = Table.SelectRows(Source, let latest = List.Max(Source[Date modified]) in each [Date modified] = latest)
    in
        #"Filtered Rows"

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • v-yingjl's avatar
    v-yingjl
    Community Support

    Hi Anonymous ,

    You can follow these steps to get the lastest file from Sharepoint folder:

    1. Connect to Sharepoint folder, choose transfrom data

    2. In power query, select the date modified column and filter it as 'Is latest'

    3. Now you will get the lastest file content in power query, expand and import it into power bi to get the whole data.

     

    Best Regards,

    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable
      Thanks but can you give me the Power Query for it please?
      • v-yingjl's avatar
        v-yingjl
        Community Support

        Hi Anonymous ,

        The power query code is like this:

        let
            Source = SharePoint.Files("https://xxx.sharepoint.com/sites/xxx", [ApiVersion = 15]),
            #"Filtered Rows" = Table.SelectRows(Source, let latest = List.Max(Source[Date modified]) in each [Date modified] = latest)
        in
            #"Filtered Rows"

         

        Best Regards,
        Community Support Team _ Yingjie Li
        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.