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.
Solved! Go to Solution.
@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:
@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:
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.
Hello,
Here’s a flow that can change only the column separator commas to a different delimiter in similar CSV files with quotes around the comma-containing lines. It only uses a few actions to do this, even on large CSV files.
And you can make more files put quotes around the comma-containing records if you save them as a text file.
Once all the correct commas are replaced it’s pretty easy to parse the entire file in a single Select action.
User | Count |
---|---|
87 | |
38 | |
23 | |
20 | |
16 |
User | Count |
---|---|
128 | |
50 | |
47 | |
35 | |
25 |