Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
jcamilo1985
Helper III
Helper III

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 separator, and others;

 

jcamilo1985_0-1677676781695.png


If I call a personalized column as I can use CSV.Documes to indicate several separators to the function.

Any help will be important. Thank you

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

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=";"])

vjingzhang_0-1677812168973.png

 

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.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

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=";"])

vjingzhang_0-1677812168973.png

 

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.

Thank you very much for the answer, it really works, I was hoping that the csv.document function would manually admit the option of several separators as it says in the documentation so as not to have to resort to an if, but the solution is good, thank you very much again

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors