cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
virakones
Resolver II
Resolver II

How to split & parse CSV file with comma inside a value?

Hi,

 

Running into some challenges attempting to parse through a CSV file that is using the expression split( outputs( 'CSVData'), ',') in a Compose action.

 

In the example below, I have some values that contain a comma, so the expression will inadvertently split the value itself along the comma.

 

CSVData: Value1,Value2,"Value,3",Value4

 

The split will create an incorrect array:

 

[

"Value1",

"Value2",

"Value",

"3",

"Value4"

]

 

What are some ways to avoid the above? Ideally it should remain "Value,3" - I imagine using the double quotes (") in the CSV would be a starting point? Looking to keep it within just standard actions available in power automate.

1 ACCEPTED SOLUTION

Accepted Solutions
virakones
Resolver II
Resolver II

@PrasadAthalye

Following up to the solution here: Solved: Re: Setting up specific expression to remove comma... - Power Platform Community (microsoft....

As mentioned in the thread, the final "ReplacedText" is my CSV file entirely missing commas - which I still needed intact for later use in the flow. I only wanted to replace the extra commas in the values itself as they appear, and then keep my CSV largely intact.

However, I noticed that when the CSV was split into an array from the double quotes (") it managed to create a consistent pattern, specifically when I was flipping through the Apply to Each Stage of the solution. 

Apply to Each 1/10 - CSV Data (Remains intact)

> Apply to Each 2/10 - Value,1 (Comma should be replaced here)

 > Apply to Each 3/10 - CSV Data (Remains intact)

  > Apply to Each 2/10 - Value,2 (Comma should be replaced here)

etc.


This helped me find an addition to the solution using an incrementing integer in a Do Until loop using Mod expression in a condition to detect whether the increment is odd or even (if odd, do nothing, if even replace comma).

1. (CSVCount) Add Initialize Integer Variable after creating CSV array variable to use to count against: 

length( variables( 'CSVDataArray' ) )

2. (arrayCount) Add Initialize Integer Variable to Increment with later: starting value 1 

 

3. Put Apply to Each in "Do Until" loop: Do until arrayCount is greater than CSVCount

 

4. Inside Apply to Each, add a condition to check whether arrayCount is odd or even using Mod:
mod(variables('arrayCount'),2) is equal to 1 (if equal, its odd, if not equal, its even)

5. If yes, Append to ReplacedText as is (current item of Apply to Each - the intact CSV data)

6. If no, Replace the comma in the value, then append to ReplacedText
replace(variables('TextAfterSplit'), ',', '')

 

7. After condition, still inside Apply to Each, increment variable arrayCount by 1

 

8. Finally compose the ReplacedText 

Image Below:

addon.jpg

View solution in original post

2 REPLIES 2
virakones
Resolver II
Resolver II

@PrasadAthalye

Following up to the solution here: Solved: Re: Setting up specific expression to remove comma... - Power Platform Community (microsoft....

As mentioned in the thread, the final "ReplacedText" is my CSV file entirely missing commas - which I still needed intact for later use in the flow. I only wanted to replace the extra commas in the values itself as they appear, and then keep my CSV largely intact.

However, I noticed that when the CSV was split into an array from the double quotes (") it managed to create a consistent pattern, specifically when I was flipping through the Apply to Each Stage of the solution. 

Apply to Each 1/10 - CSV Data (Remains intact)

> Apply to Each 2/10 - Value,1 (Comma should be replaced here)

 > Apply to Each 3/10 - CSV Data (Remains intact)

  > Apply to Each 2/10 - Value,2 (Comma should be replaced here)

etc.


This helped me find an addition to the solution using an incrementing integer in a Do Until loop using Mod expression in a condition to detect whether the increment is odd or even (if odd, do nothing, if even replace comma).

1. (CSVCount) Add Initialize Integer Variable after creating CSV array variable to use to count against: 

length( variables( 'CSVDataArray' ) )

2. (arrayCount) Add Initialize Integer Variable to Increment with later: starting value 1 

 

3. Put Apply to Each in "Do Until" loop: Do until arrayCount is greater than CSVCount

 

4. Inside Apply to Each, add a condition to check whether arrayCount is odd or even using Mod:
mod(variables('arrayCount'),2) is equal to 1 (if equal, its odd, if not equal, its even)

5. If yes, Append to ReplacedText as is (current item of Apply to Each - the intact CSV data)

6. If no, Replace the comma in the value, then append to ReplacedText
replace(variables('TextAfterSplit'), ',', '')

 

7. After condition, still inside Apply to Each, increment variable arrayCount by 1

 

8. Finally compose the ReplacedText 

Image Below:

addon.jpg

View solution in original post

Hi,

 

Thanks for your follow up post! I am glad you were able to find a solution for your issue. Hopefully this will prove useful for future communities users who are having similar issues.

 

Regards,

 

Alex

 

-------

 

Community Support Team _ Alex Rezac
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (24,039)