Locked lesson.
About this lesson
Importing data from a text file into an Excel table.
Exercise files
Download this lesson’s related exercise files. You can download source data files for the course from the resources section of your Lessons page.
Getting data from Text files.xlsx19.7 KB Getting data from Text files - Completed.xlsx
30.5 KB GoSkills Power Query Source Data.zip
8.6 MB
Quick reference
Getting Data from Text Files
An overview of importing and cleaning data from a text file.
When to use
When you use a text file as a data source for your query and must clean up the (often) messy results so the data can be loaded into the data model.
Instructions
Getting started
- Create a new query --> From File --> From Text/CSV --> browse for the file to import
- When greeted by the preview window, click Edit
Helpful tips for cleaning up text files
Removing irrelevant rows
- Go to Home --> Remove Rows
- Can be used to remove Top x, Bottom x, or even alternating rows
Tips for removing characters from text
- Leading and trailing whitespace: right click the column header --> Transform --> Trim
- Internal whitespace: right click the column header --> Replace Values --> replace 2 spaces with 1
- Non-printing characters: right click the column header --> Transform --> Clean
Splitting data into columns
- Right click the column header --> Split Column
- Options include splitting by delimiter or by a specified number of spaces
- You can also split at just the left most, right most or repeating intervals
Merging columns
- Select the columns to merge (hold down CTRL or SHIFT when clicking to select multiple columns)
- Right click any of the selected column headers --> Merge Columns
- Options include adding a separator character
Other tips
- Use Promote First Row to Headers to give the columns decent names
- Rename column headers by double-clicking the header name and typing a replacement
- To change the data type, click on the symbol and choose the data type you want
Setting data types
- The symbol to the right of the column header indicates the data type (e.g. ABC is text, 123 is whole number, $ is currency, a calendar grid is date, etc.).
- Change a data type by clicking the symbol and choosing a new one
- Set a data type with Locale by clicking the symbol and choosing Using Locale --> choose the Data Type (e.g. Date) and the Locale (e.g. English United States)
Errors
- Appear in green font
- Click on the white space next to Error to display the actual error message
- Remove all rows that contain errors via the Remove Rows function --> Remove Errors
- Errors should be removed as soon as they are caused before other filtering operations
Filtering
- Use the filter arrows to the right of the column header to remove rows
- Filters can be used to remove values (including nulls) but not errors
Hints & tips
- You can go back through the steps applied to the query in the Query Settings window
- Any query step can be deleted by clicking on the “X” to the left of the query step
- It is recommended that you always remove rows with errors before filtering out rows with nulls
- If you filter out the nulls first and then trigger an error, the data after the row on which the error was triggered is cut off and removed, and then not all of your data will be loaded into the model
- You may have to remove errors and nulls multiple times after new steps are applied
Lesson notes are only available for subscribers.