Forum Discussion

doctornick0's avatar
doctornick0
Frequent Visitor
7 years ago
Solved

Add column to convert source name to date

Hi, everybody,   When importing a folder of CSV files, I need to add a column to convert the file names (which are in my Source.Name column in Power Query) to dates, as the CSV files are snapshot f...
  • ImkeF's avatar
    7 years ago

    Yes: You add a custom column with this code:

     

    Text.Start(Text.AfterDelimiter([Column1], "_"),2)

    Replace "Column1" with the name of your column.

     

    You can paste this code into the advanced editor and see how it works:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkhMTlUISi3ILypRcEksSYw3MDUwNbTQSy4uU4rVgchrQ+S1IfKGRoYw+VgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Day", each Text.Start(Text.AfterDelimiter([Column1], "_"),2))
    in
        #"Added Custom"