cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Change the delimiter when creating a CSV file

I am querying a SharePoint List and using the Create CSV Table action to generate a CSV file.

However I want the file to be pipe("|") separated.

 

Is there a way to change the delimiter when creating a CSV file. I would greatly appreciate any advise on this.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Admin_A
New Member

If you intend to do this with the data contained in a SharePoint List, you could :
1) Get your elements with the SP connector;

2) Initialize a string variable with the columns names you would like, e.g. "name;surname;email" and by hitting enter to add a carriage return;

3) Use "Apply to each" on the value element returned by the SP Get elements block;

4) In the apply to each loop, use an "Add to string variable", where the content would be the dynamic fields extracted from SP, separated with ";" and with a carriage return at the end of the line (hit enter)

 

Then you can add your string variable as the content of an attachment for instance.

Hope this helps !

View solution in original post

Hi @Admin_A 

thank for your reply.

 

I had taken a similar route in order to reach the same destination.

I'm creating the CSV table as intended by MS Flow, but I'm using 'custom columns'.

On each header/column I'm adding some special characters (note that these are also forbidden in the SP list, via column validation).

nihkel_0-1598950790454.png

Note the pipes encapsulating the content (everywhere except the line jump, since I'm using the default carriage returns on the CSV).

My aim was to create an easily replaceable set of characters (in my case, pipe-comma-pipe) I could look for, and then replace it as a whole for the character I need to be used as separator.

 

So next step is a compose action with a replace expression for the 'character set' I created.
I look for |,| and then replace it with my desired separator.
I also didn't needed to take the carriage retun into account since I'm using the default ones created for each line on the CSV.

 

I hope thi can help someone 🙂

View solution in original post

12 REPLIES 12
v-yamao-msft
Community Support
Community Support

Hi @Anonymous,

 

By default, a comma is used to separate the items. If you want the file to be pipe separated, you could use a replace function to replace the comma with a pipe.

 

Under the Create CSV table, add a Compose action, and use the following code:

replace(body('Create_CSV_table'),',','|')

 

Then in the email body, select the output from the Compose action.

1.PNG

 

Please have a try with it on your side.

 

 

Best regards,

Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

HI Mabel,

 

Thank you for the reply but the solution proposed by you will also replace any comma in the input file with a pipe ('|').

I just want the separator to be changed from comma to pipe while keeping the "commas" elsewhere intact.

nihkel
Advocate I
Advocate I

Any updates on this topic?

This is 2 years old and a pretty basic feature.

 

Has anyone come up with a working solution that doesn't reaplace all particular characters in the CSV but only the delimiter/separator?

 

Thanks in advance for your help,

Best regards

I am also looking for a solution for this. Any update?

I was kindly pointed to some potential workaround in a similar thread:

https://powerusers.microsoft.com/t5/Power-Automate-Ideas/Changing-the-delimiter-in-Create-CSV/idc-p/...

 

Hope this helps @SwapnaNethi 

Admin_A
New Member

If you intend to do this with the data contained in a SharePoint List, you could :
1) Get your elements with the SP connector;

2) Initialize a string variable with the columns names you would like, e.g. "name;surname;email" and by hitting enter to add a carriage return;

3) Use "Apply to each" on the value element returned by the SP Get elements block;

4) In the apply to each loop, use an "Add to string variable", where the content would be the dynamic fields extracted from SP, separated with ";" and with a carriage return at the end of the line (hit enter)

 

Then you can add your string variable as the content of an attachment for instance.

Hope this helps !

Hi @Admin_A 

thank for your reply.

 

I had taken a similar route in order to reach the same destination.

I'm creating the CSV table as intended by MS Flow, but I'm using 'custom columns'.

On each header/column I'm adding some special characters (note that these are also forbidden in the SP list, via column validation).

nihkel_0-1598950790454.png

Note the pipes encapsulating the content (everywhere except the line jump, since I'm using the default carriage returns on the CSV).

My aim was to create an easily replaceable set of characters (in my case, pipe-comma-pipe) I could look for, and then replace it as a whole for the character I need to be used as separator.

 

So next step is a compose action with a replace expression for the 'character set' I created.
I look for |,| and then replace it with my desired separator.
I also didn't needed to take the carriage retun into account since I'm using the default ones created for each line on the CSV.

 

I hope thi can help someone 🙂

Thanks, this was very helpful. We did almost the same thing, although for some reason, a single replace statement looking for |,| did not clean all the records. Where we had comment fields with commas internally, we needed two more replace statements.  We also switched to the ^ symbol, since some of our comment fields also contained pipes! So our three replace/compose statements after the create csv table action were: 

replace(body('Create_CSV_table'), '^,^''^')   This replaced ^,^ with a single ^
replace(outputs('Compose'), ',"^''')  This searched for "^, and replaced it with nothing
replace(outputs('Compose_2'), '"''')  This searched for a double quote mark, and replaced it with nothing.
takolota
Impactful Individual
Impactful Individual

Hello All,

I ran into similar issues when pulling CSV data in from Power Automate Desktop with commas in the actual data. I wanted to change the delimiter so I could more easily parse the data without commas in the actual data messing things up.

Here's a link to the scope/flow I built so anyone can easily select their CSV data, enter a new delimiter, and get the new delimiter separated data from the final compose action without the usual errors. The file data just needs to have double quotes around any of the records with commas in them or be converted to a text file that automatically applies quotes to those records.
https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Change-CSV-File-Data-delimiter/m-p/14429...

arielbelaus
New Member

Hello all!

I'm exporting a CSV from a paginated Report and I need to replace the comma delimiter to ~. I tried with a compose formula replacing the , with the ~ but I have some data with , and I don't want to replace those.

Any ideas or solutions about it?

Thanks

takolota
Impactful Individual
Impactful Individual

@arielbelaus 

 

You can try my template for changing the CSV delimiter here:

https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Change-CSV-Data-Delimiter/m-p/1442954#M5...

It’s set to work even if there are commas in the data. You may have to copy the rest of your flow into the template flow though, as expressions in the template scope are often messed up when you try to copy it into an existing flow.

I could figure it out by changing the commas of the columns for another symbol in my query. Then, with a step of my flow, change the delimiters, and then with other step in the flow change to commas the symbol that I put with the query

Thanks!

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (2,932)