cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jsdom
Frequent Visitor

Convert CSV Column data type to string

Hi,

 

I have successfully parse a json and converted it to a csv file and a text file (.txt). The problem is, there are two columns that are being converted as integer when i open the csv file in excel. 

 

In parse JSON, the types are already "string".

jsdom_3-1603195633897.png

 

 

 

As you can see on the image below, Seq 1 & Seq 2 are of type string

jsdom_0-1603195287819.png

But when i open the csv file in excel , those columns are being treated as integer (which is not OK. )

 

In here, the Seq 1 & Seq 2 are automatically right aligned which means they are treated as integer when i open the file in excel. Unlike Seq3, which is left aligned and is being treated as string.

jsdom_1-1603195469429.png

 

I tried to convert the column to String but i am not sure if i am doing this right. The flow runs, but i still have the same problem.

jsdom_2-1603195580931.png

 

Any help is much appreciated.

 

Kind regards,

 

jsdom

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

You need to use the Excel tab trick as discussed in this post:

 

https://superuser.com/questions/318420/formatting-a-comma-delimited-csv-to-force-excel-to-interpret-...

 

I built a flow and tested it with data like yours and it works well:

 

ExcelToText.png

 

Excel interprets it correctly:

 

ExcelToText2.png

 

Note that the initialize variable step literally has a tab copied and pasted into it. So the code looks like this:

{
    "inputs": {
        "variables": [
            {
                "name": "charTab",
                "type": "string",
                "value": "\t"
            }
        ]
    }
}

 

Hope this helps.

View solution in original post

9 REPLIES 9
Pstork1
Most Valuable Professional
Most Valuable Professional

In the Create CSV action add double quotes around those fields that are being interpreted as numbers.  That way when you open the CSV in Excel they will be implicitly read as strings.  The problem is that the CSV doesn't include any type information.  It assumes the data type of each entry based on the entry itself.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
jsdom
Frequent Visitor

@Pstork1 

 

Thanks! But unfortunately, those columns have double quotes now in them. I also tried to put single quote in the beginning of create csv, but the single quote appeared too. I also tried putting and equal sign, and equal + single quote.. but still the same. 

 

jsdom_0-1603201058043.png

 

Kind regards,

 

 

 

Paulie78
Super User
Super User

You need to use the Excel tab trick as discussed in this post:

 

https://superuser.com/questions/318420/formatting-a-comma-delimited-csv-to-force-excel-to-interpret-...

 

I built a flow and tested it with data like yours and it works well:

 

ExcelToText.png

 

Excel interprets it correctly:

 

ExcelToText2.png

 

Note that the initialize variable step literally has a tab copied and pasted into it. So the code looks like this:

{
    "inputs": {
        "variables": [
            {
                "name": "charTab",
                "type": "string",
                "value": "\t"
            }
        ]
    }
}

 

Hope this helps.

jsdom
Frequent Visitor

@Paulie78 

 

Thank you so much! That really helps. 

 

jsdom_0-1603203389164.png

 

Kind regards,

 

@jsdom No worries, glad you got it sorted.

Anonymous
Not applicable

I didn't think literally coping tab in the value would do the trick...

Than you

Hello @Paulie78,

 

How did you set /t in Chartab string variable? i tried to set space there but it couldn't work.

Typed a tab in another application (e.g. notepad) and then copy and pasted that tab into a Power Automate variable. But actually it would be easier and more efficient to use an expression: 

decodeUriComponent('%09')

Will give you a tab.

This has been one, if not the most frustrating thing I have ever attempted to fix.  With that said, after 2 days of trying this solution fixed this issue and work beautifully.  Thank you. 

David K Akridge
Chief Information Officer, Mobile County Public Schools

Helpful resources

Announcements

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (2,745)