Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Loading specific files into PowerBI

Hello   Can you tell me please how to load the newest file from a folder C:\Directory to PowerBI that have filename File1*.xlsx, the newest File2*.xls etc?   Thanks!
  • v-jingzhang's avatar
    4 years ago

    Hi Anonymous 

     

    Try these codes:

    let
        Source = Folder.Files("C:\Users\YourFolder"),
        #"Filtered Rows" = Table.SelectRows(Source, each Text.StartsWith([Name], "A") or Text.StartsWith([Name], "B")),
        #"Inserted First Characters" = Table.AddColumn(#"Filtered Rows", "First Characters", each Text.Start([Name], 1), type text),
        #"Grouped Rows" = Table.Group(#"Inserted First Characters", {"First Characters"}, {{"Newest Date Created", each List.Max([Date created]), type nullable datetime}, {"GroupTable", each _, type table [Content=binary, Name=text, Extension=text, Date accessed=nullable datetime, Date modified=nullable datetime, Date created=nullable datetime, Attributes=nullable record, Folder Path=text, First Characters=text]}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.SelectRows([GroupTable], let latest = [Newest Date Created] in each [Date created] = latest)),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Folder Path", "First Characters"}, {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Folder Path", "First Characters"})
    in
        #"Expanded Custom"

     

    Insert a column to help group by. You can modify this step per your need. 

    Remove columns except for Custom column and expand it to get the filtered result.

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.