0% found this document useful (0 votes)
38 views14 pages

Importing-Data in Excel

This document provides tips on importing data into Excel from various sources such as databases, CRM systems, and websites. It discusses best practices for importing dates and numbers from text files, including converting data to the proper data types and formats. The document also covers setting up imports properly in Power Query and the Text Import Wizard, and touches on importing from other sources like databases. Key recommendations include assessing data quality after import, checking that dates are recognized correctly, and setting the right locale in Power Query to properly handle dates and numbers during import.

Uploaded by

Amanda Rodrigues
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
38 views14 pages

Importing-Data in Excel

This document provides tips on importing data into Excel from various sources such as databases, CRM systems, and websites. It discusses best practices for importing dates and numbers from text files, including converting data to the proper data types and formats. The document also covers setting up imports properly in Power Query and the Text Import Wizard, and touches on importing from other sources like databases. Key recommendations include assessing data quality after import, checking that dates are recognized correctly, and setting the right locale in Power Query to properly handle dates and numbers during import.

Uploaded by

Amanda Rodrigues
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

Reading 1.

Importing data
Importing data from various databases, crm systems, websites, and other sources is a huge
part of what many people do in Excel. Here you will find our tips on how to go about
importing data into Excel.

Section Description Pro Tip

Import dates and numbers from text This section expands on best Convert data to dates, those that
files practices as related to importing align right are seen as dates by
dates and numbers. Excel.

Set up imports properly (Power Here we elaborate on setting up Check your data before you set up
Query & Text Import) imports in Power Query and the old your query to make sure your
school Text Import Wizard. formats match the source data.

Importing from other sources The final section is a quick dive into With any major database system,
different databases and sources filter out the information you need in
which can be called up by a query. the system before going to Excel.

Pro tip: Do not open CSV’s by a simple double-click!


• No control over import
• Import cleanup becomes a manual process

1.3.1 Importing data from text files


Once your data is in Excel (or perhaps PowerQuery or PowerPivot), the first thing we
recommend you to do is assess the quality of your data. It is impossible to come with an
exhaustive list of possible things to look out for, but let’s address a couple of them.

Dates and Numbers


Are all dates recognized as true dates? Excel certainly tries to help you when you import
dates, but if you get it wrong, unexpected things may happen. Especially if you select a date
order which does not coincide with the order of your raw data. The date formatting differs in
various countries around the world. Getting it right can be difficult.

Dates
For any dates Excel has successfully converted to a data, the filter drop-down will
automatically group them in periods like years and months. So if it doesn’t do that, beware!
Worked out example:

READING 1.3 | IMPORTING DATA | PAGE 1 OF 14


This set of dates for instance is currently not recognized by Excel as true dates, in fact they
are all treated as text values:

If you handle the transformation of those textual dates wrongly, Excel creates this mess:

Anything it succeeded to convert to a date is left-aligned, anything Excel failed to translate is


right-aligned. If you click that auto filter drop-down, this is what you get:

READING 1.3 | IMPORTING DATA | PAGE 2 OF 14


Notice the mix between years and textual items containing an entire date. It’s the years you
want to see, anything else is an indicator that something went wrong.
You should ask yourself, are these values actually correct? Note that in column A, the date is
in Month/Day/Year format. Let’s have a look at a simple check against the transformed
data: we retrieve the month from the dates using the MONTH function (columns D and G):

As you can see, column D does contain a calculated month for some of the dates, but those
months are all wrong! Column F does contain true dates (all right-aligned and no left-aligned
text values left) and all of Column G returns the correct months, indicating the
transformation we did to get column F was indeed the right one.
So, don’t let seemingly correctly translated dates fool you, check and double-check.

Numbers
As simple as it may seem, even importing numbers has challenges. For example, you may
be using different decimal and thousand separators than your source data carries. This is
especially true for information downloaded from websites or from browser-based
applications like SAP. Especially if you’re in an international organization, formatting of
numbers in text-files can vary depending on their source and upon local (browser) settings.
Let’s assume our numbers contain a period as the decimal separator and a comma as
thousands grouping symbol. Then this bit of data can be a challenge to convert:

READING 1.3 | IMPORTING DATA | PAGE 3 OF 14


If you transform this data to numbers without paying attention, you may end up with this:

Note how all the numbers which happened to have three decimals are off by a factor of one-
thousand! Excel assumed the comma wasn’t the decimal separator, but the thousands
grouping symbol.

1.3.2 Setting up imports to handle dates & numbers

These problems are very common when trying to import data from text files, like typically
files with an extension of .csv or .txt. In order for Excel to properly convert dates and
numbers, you have to use the right settings.

PowerQuery
To use PowerQuery to import text files, and we highly recommend you do so, you must click
the New Query button (in newer Excel versions this button has been renamed to Get Data).
Before you do so, it is best if you check out your raw text file, using Notepad for instance.

READING 1.3 | IMPORTING DATA | PAGE 4 OF 14


Try to determine important things like:

• List separator (the separator that separates the columns)


• Date separator
• Date order
• Decimal separator
• Thousands separator

PowerQuery expects data in text files to have the same formatting as the country (Region)
you selected in your Windows settings:

READING 1.3 | IMPORTING DATA | PAGE 5 OF 14


Along with this setting (which is called “Locale” in PowerQuery) come default settings for
date and number formatting. So before starting an import, click that New Query, or Get Data
button and choose “Query Options…”:

Now your task is to select the correct Locale. It isn’t very easy to find the one which happens
to correspond with your combination, but luckily, someone sorted this out and there is a list
available here: Listing Windows Language Code Identifiers And Their Associated Date And
Number Formats With M In Power BI/Power Query

READING 1.3 | IMPORTING DATA | PAGE 6 OF 14


This is what the output of that article’s downloadable Excel workbook looks like:

PowerQuery also allows to set the locale during the import itself.
In the Query editor pane, right-click the column in question and choose “Change Type…”,
“Using Locale…”:

Allowing you to set both the data type and the locale to use during the translation to that
data type:

READING 1.3 | IMPORTING DATA | PAGE 7 OF 14


After selecting the locale which has a decimal separator and date syntax corresponding to
the file you wish to import you click New Query (or Get Data), From File, From CSV:

In the next window you simply browse to your file and open it:

READING 1.3 | IMPORTING DATA | PAGE 8 OF 14


PowerQuery is likely to recognize the delimiter (also often called list separator, the character
that separates the columns) and set it for you:

Rather than clicking Load, the best next step to take now is click Transform Data. This will
open up the PowerQuery window, with a preview of your current data. It is important to know
that it is here that you should be filtering out (or simply deleting) any content you do not
need for your analysis.

Also important: Make sure each column is showing the correct data type as indicated by the
small icons next to the column headings:

READING 1.3 | IMPORTING DATA | PAGE 9 OF 14


In the screenshot above, the data type for the Date column is incorrect; it is set to text. Click
the icon to select the correct date type:

PowerQuery will try to convert the dates according to the locale you chose. If your result
contains a lot of errors:

Double-check the locale you chose, it was probably one with a different date syntax or order
than the one your data is written in.

The text import wizard


The old-school text import wizard is still available, it is opened by using this button:

READING 1.3 | IMPORTING DATA | PAGE 10 OF 14


It looks like this:

Step 3 of the wizard allows you to set the data format:

You can click each column individually and set the data format. Note the drop-down button
next to Date, it allows you to choose the order of the elements of a date. Also, note the
“Advanced…” button. This button allows you to set the decimal and thousands separators:

READING 1.3 | IMPORTING DATA | PAGE 11 OF 14


1.3.3 Importing from other sources, like databases
Many companies use databases for all sorts of data storage. If you need company data, ask
yourself whether there might be a database system holding that data. If that is the case, ask
your IT department to grant you access to the needed information. Especially the larger
systems (like SAP, ORACLE, SQL Server) are often locked down against direct query’s. This
is done to make sure the system that is based on these databases keeps running and is not
bogged down due to an error in a query issued by an inexperienced user.

Another good reason to contact IT when it comes to these large databases is that the data
you need might not be easy to find. Corporate databases can contain hundreds of tables
and it is very likely that your data needs to come from a combination of them, using the right
relationships. IT can usually predefine all of this for you.

Also, in this phase it is very important to think about which data you need precisely and in
what format. For instance, if your goal is to simply report a summary of sales per
department, it makes no sense to have the query return all individual entries of items sold.
You need an aggregated dataset with just the information you wish to be able to report (and
filter) on. If there are 10 departments, all you need is 10 rows of data per period your report
is supposed to display.

While you’re at it, try to define which data type you expect to get for each column (Field) of
your data. Getting the correct datatype from the query will save you a lot of hassle later on.
All that being said, getting database data is fairly simple. Click New Query (Get Data), From
Database and choose the database type:

READING 1.3 | IMPORTING DATA | PAGE 12 OF 14


Let’s show you what happens if you choose from Microsoft Access Database:

Example: PowerQuery opens a File browse window from which you need to select the
correct Access database file:

Click Import and the PowerQuery Navigator window opens:

READING 1.3 | IMPORTING DATA | PAGE 13 OF 14


Note the various options you have here, for example that you can click “Select related
tables”.

When you’ve chosen the correct tables, click the transform data button to proceed.
Note, that setting up a direct connection to tables in the database isn’t recommended, a
table may contain hundreds of millions of records! It is better to first set up a query (or View
or Stored procedure, naming depends on the database brand) in the database application
itself, to make sure you filter the data and get only the data into Excel which you actually
need for the report. Setting up a query is often a step that must be done by the Database
Administrator or owner.

READING 1.3 | IMPORTING DATA | PAGE 14 OF 14

You might also like