CSV decimal dot in Excel - excel

I have a CSV file with the following values:
3271.96;274;272;1;1;0;1;0.071690;0;0;0;0;0;0;1.753130;1.75;0;1.75;
But when I open the file with Excel I get this:
3271.96 274 272 1 1 0 1 0.071690 0 0 0 0 0 0 1.753.130 1.75 0 1.75
Why is "1.753130" converted into "1.753.130"? (1.753130 is a decimal number) how can I "force" Excel to understand that these are decimal numbers?
I create the CSV file with a web application, so is difficult just modify my Excel configuration because many people visit my website and download the CSV file to their machines.

For users seeking to this question with newer Excel versions like Excel 365...
As written at Professor Excel you could activate/restore "From Text (Legacy)" in the settings.
My prefered solution
File - Options - Data
Then you will be able to get the old import wizard... legacy but in my opinion more intuitiv.
Other possibilities
At that linked Professor Excel website there are also shown other possibilities. With Excels new import dialog, if you have several columns with numbers all in a different locale to your computers locale settings, then it will be much more effort to do the import.
With the old wizard you are set within a minute. With the new import dialog I haven't found yet a method to be as fast as with the legacy import method.

here is the answer I used:
go to Data tab on excel sheet.
click on from Text button.
then select text or csv file.
then the import wizard will come out. select comma separated or space separated option.
then select delimiter. (this is better if you don't want it to have problem while importing decimals)
then in the next window there will be Advanced option for General column type. Click the advanced button and choose how to separate decimals and thousands.
Change the decimal separator to a "." and remove the thousand separator with a space.

As of now (Sep, 2020), I managed to do this in a slightly different way. I'm using Excel from a Office 365 subscription.
With your Excel sheet open, go to:
Data (tab) > From Text/CSV (Get & Transform Data section)
Select your file (.txt or .csv), then you'll have 3 options:
File Origin: probably you won't have to change this
Delimiter: choose whatever your delimiter is (probably comma)
Data Type Detection: change this to "Do not detect data types"

rename the csv to .txt
open excel
go to file-->open and point to your txt file
go through the steps of importing it
make sure to use ; as the delimitter

I had the same problem but solely this solution didn't work out for me.
Before that I had to go to Office icon -> Excel Options -> Advanced and set the thousand delimitter from "." to "" (nothing).

There is a more straight forward method to import data from text/csv into Excel (2017):
Open a blank book in Excel and click in import data from text/csv.
Select the file.
The assistant will show a preview of the data, but if you are importing from a csv with decimal / scientific numbers all will be recognized as text.
Before importing, click on edit, you will see an Excel spreadsheet with a preview of your data.
If you click on the advanced editor button, a new window with the query Excel does will appear.
You will see something like:
let
Origin = Csv.Document(File.Contents("C:\Users\JoseEnriqueP\Downloads\evaluation_output.txt"),[Delimiter=",", Columns=8, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Updated type" = Table.TransformColumnTypes(Origin,{{"Column1", Int64.Type}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}})
in
#"Updated type"
Then, you can write down directly the types for each column:
- Text: type text
- Integers: Int64.Type
- Decimals: Double.Type
The import code would be as follows:
let
Origin = Csv.Document(File.Contents("C:\Users\JoseEnriqueP\Downloads\evaluation_output.txt"),[Delimiter=",", Columns=8, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Updated type" = Table.TransformColumnTypes(Origin,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}, {"Column4", type text}, {"Column5", Double.Type}, {"Column6", Double.Type}})
in
#"Updated type"
By doing this, you will get directly your data into Excel.

If you have a newer version of Excel(e.g. Office 365) and you don't need to correct the file's encoding, here is what worked for me:
open the .csv file by double clicking it in your file explorer
select the column(s) containing decimal numbers
use Find and Replace to change all dots (.) to a comma (,) sign
This assumes that no other data transformations are needed(which would likely require going through the import wizard), and that the file's encoding is correctly recognized by Excel.
If encoding is also an issue, do the following before the steps above:
edit the file in Notepad++
open the Encoding menu tab
choose a desired value to convert the file's encoding
Some of the other answers work also, but for sheer simplicity, you can't beat the Find and Replace method. No matter what you do, here is the most important step: Live long and prosper!

Something that worked for me in 2012 version of Excel is that when you import data, you have the option to open a 'Transform Data' box. In this box on the right side panel, you can see a list of 'Applied Steps'. These are the steps which excel applies on the source file. You can remove the steps from this list which are causing problems.
I had a problem with excel ignoring the decimal point while importing from my text file but this resolved the issue.

Related

Excel: Is there a way to update the table from power query even if a row is missing?

Hope you have a great day. Recently I was trying to create a report in Excel and tried to get the data needed from an HTML file. The HTML file is basically the web page where all the issues are stored then filtered in little tables with what we need for the day. I don't have the option to get the data from web directly since the company does not allow add-ins to log in to the site and grab the data from there and the Get Data from Web does not work since the security of the database pops in and does not let you to get anything, so the workaround was to save the page as HTML every time I need to make the report and overwrite the old one that is connected to the Excel Workbook.
I managed to create the needed charts of the loaded tabled from the HTML file into excel, but I stumbled on an issue on the Power Query side. The tables from the page I save the HTML file are not the same, meaning sometimes a column is missing since there was no issues for it and the database will hide it automatically from the table, so when I refresh the query it will display the error "The Column X is missing from the table". I know it is missing, but I don't want to get the data every time one column is missing and redo everything again so the chart will update correctly.
Is there a way to make a code in Power Query advanced editor so the table will update anyway even if a column is missing without needing to code/get data every time? What I'm trying to do here is to automate a process so the least amount of work to get the data, the better for me.
Thanks in advance!
*Edit: This is the source M code of the query:
let
Source = Web.Page(File.Contents("D:\AUTO.html")),
Data1 = Source{1}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data1,{{"Customer Impact", type text}, {"Yes", Int64.Type}, {"No", Int64.Type}, {"WIP", Int64.Type}, {"T:", Int64.Type}})
in
#"Changed Type"
The problem is with the #"Changed Type" step since it's trying to transform non-existing columns.
The simplest solution would be to just eliminate that step entirely and let the data come through without assigning types. That is, replace your query with this:
let
Source = Web.Page(File.Contents("D:\AUTO.html")),
Data1 = Source{1}[Data]
in
Data1
If the typing is important, you can write a more dynamic step to assign types that doesn't break. In this case, you'd need to provide details as to how that logic should work (e.g. "Customer Impact" is always present and should be text and the remainder should all be integers).

Excel wrongly read scientific formatted numbers in csv

I have a csv file with numbers written in scientific notation (ex. 2.8570890426635534e-05 ) but when i open the csv in excel ( both by opening directly and by importing data in the Data tab) the number that excel display is 2,87509E+11.
I have even tried to change the encoding format when reading the csv (ISO, WINDOWS, DOS, UTF-8, ...) but none of them seems to work properly.
Anyone knows where the problem might be ?
If you are importing using Power Query from the Data tab, after selecting to Import:
Transform
Right click on the column
Change Type / Using Locale
Data Type: Decimal Number
Locale English (United States)
In the Applied Steps menu, you will see
Changed Type
Changed Type with Locale
Delete that first Changed Type step.

Excel 2010 - load a text file "as text"

Is there anyway I can get Excel 2010 to load a text file as pure text, i.e. apply no interpretation to any field? I need to modify a large CSV file with several hundred columns (basically remove some columns). It's health data, so some of the columns are:
NHS number "123456789012", which Excel displays as 1.23E09
Hospital ID: "0123456", which Excel displays as "123456". The leading zero is important here.
Various 2 char status codes where the leading zero is imports, i.e. "01" does not mean "1".
I don't want to have to go through all 297 columns reformatting them correctly. Please help!
From main menu Data select From Text (or similar. I don't know if it is the correct label in English Excel version. On my version it is the third button from left on the Data ribbon).
Then choose your csv file. You will get a wizard where you have to choose the column separator character and especially the import format of the columns. Here you should select all columns and then choose the radio button 'Text'. This should import all data as plain text.

Export Excel data with a custom deliminator in .csv

I want to export a huge excel file as a .csv, but the data contains commas within the cells.
How do I export the excel data to a .csv with the deliminator as this |
I've tried doing the usual "save as", but it is not working for my data.
Hi Check out this method in the below link, its what I have used in the past
https://www.howtogeek.com/howto/21456/export-or-save-excel-files-with-pipe-or-other-delimiters-instead-of-commas/
Summary:
Control Panel –> Region and Language, and then click the Additional settings
When in the additional settings find “List separator”
Change this to anything you want, in your case you would want the | pipe
By definition CSV stands for Comma Delimited.
Easy alternatives that were under your nose in the Save As window are:
"Formatted Text(Space Delimited)" though this won't be appropriate if you have spaces in your cells
"Text(Tab Delimited)" it is less likely you'll have tabs in your cells and people won't type those in to excel.
If you really want the 'pipe' | then I would suggest saving as tab delimited and running some kind of find & replace on the resulting text file. This is a bit of a workaround
A even bigger workaround is to concatenate the cells using a formula on the sheet with a | involved and the save as text only that column.

Power Query: How to import numbers as text

I have a csv file to import to Power Query (250,000 records). One field contains our fee codes which are usually entered as numbers but sometimes contain characters (e.g. 17, 17A, 67, 67A, etc). When I import the file to Power Query, the field is treated as a numeric column and all the data with letters is not imported. I can convert the field to text AFTER the import - but by then it is too late and I have lost all the non numeric data. How can I tell Power Query to bring in this field as TEXT not as a number?
Is there an easy way to change the way the data is imported without having to change the data file or manually create a schema file? P.S. I am new to Power Query so this may be something simple that I have overlooked - but I really have looked!
Power Query adds an automatic type conversion step after certain data sources like CSV. If you look at the Applied Steps list you'll see that the last step is one that changes the type. You can delete that step to undo the type change.
You can also edit the step by making the formula bar visible (which can be enabled by going to the View ribbon and checking the Formula Bar checkbox) and then editing the column type. For example, if your formula was:
= Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type datetime}, {"ID", Int64.Type}})
you can change ID to be a text type by changing Int64.Type to type text.

Resources