# Impoet Text file - Keep leading zeros



## JEB85 (Sep 21, 2012)

Hi Guys,</SPAN>

I have numerous Excel files that are in the same format which I’ve merged as one text file to import into powerpivot.</SPAN>

One of the columns of data I have on the face look like numbers but I have them stored as text e.g 09312000.  This is important because I need to keep the leading zeros.</SPAN>

When I import the data into powerpivot I’m losing the leading zeros.</SPAN>

How do I get around this?</SPAN>

Thanks</SPAN>


----------



## JEB85 (Sep 22, 2012)

Anyone any ideas?  I can't find a solution for this anywhere?  Powerpivot keeps dropping all the leading zeros on import!


----------



## JavierGuillen (Sep 22, 2012)

try importing that column as text instead of a numeric type.

if you are using Excel, simply change  the data type to text on that column before saving the file.

if its CSV format, be sure to sorround your values with double quotes (as in "0900"), and then PowerPivot will respect the leading zero


----------



## JEB85 (Sep 22, 2012)

brilliant as ever javier. thanks!


----------



## JEB85 (Oct 1, 2012)

Hey Javier, I tried the solutions you suggested today (bit of a delay I know - hectic at work) and I didn't have any luck with either solution.  

The data type as text made no difference, I still lost the leading zeros.

I also tried putting the double quotes around the values e.g. "089210" and saved the files as CSV, imported into powerpivot, but then the values in Powerpivot had double quotes around them.  A convoluted approach would be to accept this method and then just use the Substitute function to replace the quotation marks with blanks.

There must be a simple solution though (perhaps I've missed something) - there must be thousands of people who import files into powerpivot and need to keep leading zeros.

Incidentally, the reason I'm not importing directly from Excel is that I'm merging multiple Excel files into one big text file to avoid the million rows hurdle.

Have you any idea what I might be doing wrong ie why I'm losing the leading zeros?

Thanks


----------



## JavierGuillen (Oct 2, 2012)

The issue here is that PowerPivot is incorrecly assuming this is a numeric value (removing the leading zero), and what we are trying to do is to signal it that it is text, in which case there is no need to remove the zero.   I have tested the approach of using double quotes in CSVs files with success, but I'm really curious as to why in your case you are getting double quotes.  It would appear that PowerPivot already understood it was text, hence the double quotes were unnecessary in your case.  I would imagine this could happen is you have some non-numeric value in any row of your column.

Is this the case?  can you post a sample of your data?

Also, not sure if you have seen this blog entry but is worth exploring in your case.  As far as your multiple Excel files have the same structure, you can 'merge' them in the data load process, and skip the manual merge:

PowerPivot from Identical Structure Excel Files


----------



## JEB85 (Oct 2, 2012)

Cust No</SPAN>Amount</SPAN>Qty</SPAN>Double Quotes</SPAN>93772900</SPAN>-47.47</SPAN>1</SPAN>"93772900"</SPAN>93772090</SPAN>-58.76</SPAN>2</SPAN>"93772090"</SPAN>93742000</SPAN>-73.39</SPAN>1</SPAN>"93742000"</SPAN>93742000</SPAN>-430.62</SPAN>1</SPAN>"93742000"</SPAN>70777028</SPAN>-25.5</SPAN>1</SPAN>"70777028"</SPAN>70777028</SPAN>-23.75</SPAN>1</SPAN>"70777028"</SPAN>70777028</SPAN>-23.75</SPAN>1</SPAN>"70777028"</SPAN>70547025</SPAN>-23.75</SPAN>1</SPAN>"70547025"</SPAN>09312700</SPAN>-31.5</SPAN>1</SPAN>"09312700"</SPAN>09312700</SPAN>-6.15</SPAN>1</SPAN>"09312700"</SPAN>09312700</SPAN>-34.85</SPAN>1</SPAN>"09312700"</SPAN>09312700</SPAN>-34.85</SPAN>1</SPAN>"09312700"</SPAN>09312700</SPAN>-26.75</SPAN>1</SPAN>"09312700"</SPAN>09312700</SPAN>-26.75</SPAN>1</SPAN>"09312700"</SPAN>85956024</SPAN>-48</SPAN>1</SPAN>"85956024"</SPAN>This is a small sample set</SPAN>The double quotes column is formula based e.g. D2=""""&A2&""""</SPAN>The file is saved as CSV</SPAN>When imported into Powerpivot the Cust No column drops the leading zeros and the Double Quotes column retains the double quotes

Thanks for your help!
</SPAN>

<TBODY>

</TBODY><COLGROUP><COL><COL><COL><COL><COL span=9></COLGROUP>


----------



## JavierGuillen (Oct 3, 2012)

Try the following

paste this in a notepad file

custno,amount,qty
"09312700",-31.5,1
"09312700",-6.15,1


save it as test.csv

then go to powerpivot, import data from file, and select the csv file just created

you should see the leading zero correctly imported on the cust no. field

with this, open the csv file you had originially saved, and ensure the customer no. is saved using the same format.  only one set of double quotes around the numeric customer no. value


----------



## JEB85 (Oct 3, 2012)

Hi Javier,

Copying and pasting the below into notepad, saving as a csv and importing into Powerpivot works great for keeping the leading zeros.

custno,amount,qty
"09312700",-31.5,1
"09312700",-6.15,1

However, I've no idea how I can replicate my data set to the same format?  I've tried putting double quotes round the customer no's, single quotes round the customer no's and neither import into powerpivot properly.

All I can think is to keep the double quotes around the numbers, import into Powerpivot, add a calculated column to substitute the double quotes with blanks.  Not ideal, when my data set is over 1 million rows.  I've searched the internet for ages and had no luck in finding a solution.

Thanks


----------



## NickyvV (Oct 17, 2012)

Well, I see your problem. You have problem converting the value from PowerPivot to csv as "0993".
Is there a possibility to use an Excel file as import instead of the CSV? You could then add the connection property IMEX=1 (in advanced properties of the connection) to let Excel ignore different datatypes in the same column.






HTH


----------



## JEB85 (Sep 21, 2012)

Hi Guys,</SPAN>

I have numerous Excel files that are in the same format which I’ve merged as one text file to import into powerpivot.</SPAN>

One of the columns of data I have on the face look like numbers but I have them stored as text e.g 09312000.  This is important because I need to keep the leading zeros.</SPAN>

When I import the data into powerpivot I’m losing the leading zeros.</SPAN>

How do I get around this?</SPAN>

Thanks</SPAN>


----------



## JEB85 (Oct 22, 2012)

Hi NickyvV, thanks for the suggestion - I would normally use Excel but the file is over 1 million records and growing.  Can you think of any other solution?  It's been driving me crazy!

Thanks


----------



## cboshdave (Aug 5, 2014)

Okay... I have read through these threads.  I guess the one question that I still have is if I create a .csv file programatically for a non-excel user and I save the values as:
"01234","Person1"
"12345","Person2"
When I open the .csv file with Excel, why would Excel drop the leading zeros?  I thought that would make it clearer to excel to treat it differently??  My users have to open this file all the time.  I need to make it easier to open and deal with rather than having an import every time.  Additionally, I need to read the file back in with their changes.  So, I don't want a bunch of extraneous data.  

Thanks,
Dave


----------



## GDRIII (Aug 6, 2014)

I have not used it, and have only had surficial discussions but, it sounds like you might be able to overcome this with PowerQuery


----------

