Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

combine csv with condition

Hello, I have folder in sharepoint with many files updated daily.   I need only csv starting with ABC and having date in the end (_YYYYMMDD.csv) In addition to that if I have _20210115.csv and  _2...
  • v-jingzhang's avatar
    4 years ago

    Hi Anonymous 

     

    AlexisOlson 's solution is great. Have you tried that? 

     

    I'd just like to make some complement on his solution per your need. The complement are:

    1. Add a step to filter out rows with errors after extracting date values. File names that don't end with (_YYYYMMDD.csv) have these errors.

    2. Add a step to filter out rows that don't start with "ABC".

     

    Here are the full codes.

     

    let
        Source = SharePoint.Files("https://xxxxxxxxxx.sharepoint.com/sites/xxxxxxxxxx", [ApiVersion = 15]),
        #"Removed Other Columns1" = Table.SelectColumns(Source,{"Name", "Content"}),
        #"Added Custom" = Table.AddColumn(#"Removed Other Columns1", "Date", each Date.FromText(Text.End(Text.BeforeDelimiter([Name], ".csv"),8)), type date),
        #"Removed Errors" = Table.RemoveRowsWithErrors(#"Added Custom", {"Date"}),
        #"Filtered Rows" = Table.SelectRows(#"Removed Errors", each Text.StartsWith([Name], "ABC")),
        #"Added Custom1" = Table.AddColumn(#"Filtered Rows", "EoM", each Date.EndOfMonth([Date]), type date),
        #"Grouped Rows" = Table.Group(#"Added Custom1", {"EoM"}, {{"Alldata", each Table.Max(_, "Date"), type table [Name=text, Content=binary, Date=date, EoM=date]}}),
        #"Expanded Alldata" = Table.ExpandRecordColumn(#"Grouped Rows", "Alldata", {"Name", "Content", "Date"}, {"Name", "Content", "Date"})
    in
        #"Expanded Alldata"

     

    Result

     

    Then, you can click on the Combine Files icon on Content column. 

     

    Best Regards,
    Community Support Team _ Jing