Load data into Power Query and set column types
Power Query basics9 minPremium
Builds on Why Power Query: record a cleanup once, repeat it every month and Import a CSV file without losing zeros and dates.
A store operations manager in Phoenix gets the daily sales file from the point-of-sale system. In the Power Query Editor its columns are called Column1, Column2 and Column3, every value is text, and the store numbers have to keep their leading zeros.
How it works
A text file carries no column types, and nothing in it marks the first line as headings. Power Query may show the headings as the first row of data and every column as text, or guess both itself: for text and CSV files it checks the first 200 rows and adds Promoted Headers and Changed Type steps. Three commands put the table right:
- Home > Remove Rows > Remove Top Rows takes out lines above the headings, such as a title.
- Home > Use First Row as Headers turns the first row into the column names.
- The icon at the left of each heading shows the column's type. Click it to pick another, or use Transform > Data Type.
| Row | A | B | C |
|---|---|---|---|
| 1 | Icon | Type | For |
| 2 | ABC | Text | Names, and codes such as 0042, even when they hold only digits |
| 3 | 123 | Whole Number | Counts |
| 4 | 1.2 | Decimal Number | Amounts and measurements |
| 5 | A calendar | Date | Dates |
| 6 | ABC123 | Any | Nothing set yet |
A value the type can't read shows as Error in the preview, so look down a column after you change its type. For dates written day first, choose Using Locale on the icon's menu and pick the file's country.
Home > Close & Load writes the result to a new sheet as a table. Close & Load To offers other places, such as a PivotTable report, or Only Create Connection for a query that other queries use.
Example
A supplier's price list before and after the two steps:
Common mistakes
- A code column left as Whole Number. Power Query's own guess, or your click, turns 0042 into 42. Set it to Text.
- Use First Row as Headers while a title still sits on top. The title becomes a heading. Remove the top rows first.
- Decimal Number for a column with a stray word, such as n/a. Those cells show Error, so replace the word first.
In short
- Remove Top Rows, then Use First Row as Headers, puts the headings where they belong.
- Each column's icon shows its type: Text for codes, Whole Number for counts, Decimal Number for amounts, Date for dates.
- Close & Load writes the result to a new sheet.
Practice
Premium4 exercises: 3 queries and 1 quiz question.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in