Forum Discussion

jcamilo1985's avatar
jcamilo1985
Helper III
3 years ago
Solved

Several separators with CSV.Documes in New Column

Good morning I hope they are very well and I am looking for guidance again. I connect to a folder that has several CSV files, the problem comes at the time of separating them because some has as a ...
  • v-jingzhang's avatar
    3 years ago

    Hi jcamilo1985 

     

    You can try below code to create a custom column. 

    if Table.ColumnCount(Csv.Document([Content],[Delimiter=","])) > 1 then Csv.Document([Content],[Delimiter=","]) else Csv.Document([Content],[Delimiter=";"])

     

    Below is the full M code of my sample. You can paste it into a blank query to check the result. 

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8i9KSS3ydNHxLEnNjckz1HHLLM7IzEtXKMpPickz0jFUyEnSUyjPL8otVorVgSu3hig3tkZRbmKNojwWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Table.ColumnCount(Csv.Document([Column1],[Delimiter=","])) > 1 then Csv.Document([Column1],[Delimiter=","]) else Csv.Document([Column1],[Delimiter=";"]))
    in
        #"Added Custom"

     

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