Sub topic 6
Promoting headers and setting column data types
This chapter assumes you can open Power Query Editor, know what an applied step is, and have already connected to an Excel workbook or a CSV file. Here you will turn raw rows into a table with proper column names and types.
Why headers and types matter
A connector returns data as it finds it. Power Query then guesses some things for you, and the guesses are sometimes wrong. Two settings decide whether the table is usable:
- Headers. Column names must come from the first row of data, not appear as
Column1,Column2, and so on. - Data types. Each column needs a type such as date, whole number, or decimal number. Types control sorting, filtering, relationships, and what DAX can do with the column.
A column left as any type is a common cause of wrong sorting and failed relationships later.
Promoting headers
A CSV file read with Csv.Document returns the header line as an ordinary row. You promote it with Table.PromoteHeaders:
let
Source = Csv.Document(File.Contents("C:\Data\orders.csv"), [Delimiter = ",", Encoding = 65001, QuoteStyle = QuoteStyle.Csv]),
Promoted = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
Typed = Table.TransformColumnTypes(Promoted, {{"OrderID", Int64.Type}, {"OrderDate", type date}})
in
TypedPromoteAllScalars = true makes Power Query convert numbers and dates in the first row to text before using them as names. Without it, a numeric header can be left unpromoted.
In the editor, use Home > Use First Row as Headers. An Excel table already carries its own headers. When you select it with Kind = "Table", you do not promote anything.
Setting data types
Use Transform > Data Type or the icon in the column header. Each choice adds a Table.TransformColumnTypes step. This example sets types on an Excel table:
let
Source = Excel.Workbook(File.Contents("C:\Data\Sales.xlsx"), true, true),
SalesTable = Source{[Item = "Sales", Kind = "Table"]}[Data],
Typed = Table.TransformColumnTypes(SalesTable, {{"OrderDate", type date}, {"Amount", type number}})
in
TypedEach pair is a column name and a type. The names are case-sensitive and must match the headers exactly.
| Editor choice | M type |
|---|---|
| Whole Number | `Int64.Type` |
| Decimal Number | `type number` |
| Fixed decimal number | `Currency.Type` |
| Date | `type date` |
| Date/Time | `type datetime` |
| Text | `type text` |
| True/False | `type logical` |
The order of steps
Set types after promoting headers. If you set a type first, the step refers to Column1, and promoting headers afterward breaks it.
Common errors
Expression.Error: The column 'X' of the table wasn't found. The header text changed, or it has a trailing space. Rename the column or edit the step.DataFormat.Error: We couldn't convert to Number. A cell holds text such asN/Aor1,5where a number is expected. The cell showsErrorafter the type step. Use Replace Errors, or fix the source.- Dates read as the wrong day and month.
03/04/2026can mean 3 April or 4 March. Use Change Type > Using Locale and pick the locale that matches the file. - Types lost after a column rename. Power Query usually updates the step, but a manual M edit may not. Check the type step after you rename.
Basic cleaning
Once types are set, a few steps cover most cleanup:
- Trim text columns to remove stray spaces.
- Remove blank rows and remove duplicates where the data requires it.
- Remove errors or replace them, after you understand why they occurred.
Exercise
A CSV file loads with columns named Column1, Column2, and Column3. The real names are in row 1. You then set OrderDate to type date and get an error saying the column wasn't found. What went wrong, and how do you fix it?
Show answer
The header row was not promoted, or the type step ran before promotion, so the step looked for OrderDate while the column was still called Column2. Promote the first row with Table.PromoteHeaders (Use First Row as Headers), then apply the type step so it refers to the real column names.
Exercise
A column of dates shows Error in some rows after you set it to type date. Several values look like 13/04/2026. What is the likely cause, and which tool fixes it?
Show answer
The file uses day/month/year, but the default locale reads month/day/year, so 13 cannot be a month. Use Change Type > Using Locale and select a locale that matches the file, such as English (United Kingdom).