Sub topic 6
Promoting headers and setting column data types
This chapter assumes you can open Power Query Editor in Power BI Desktop, you know what an applied step is, and you have already connected to an Excel workbook or a CSV file. It covers the two steps that follow almost every file connection: turning the right row into column headers, and giving each column the correct data type.
Why these two steps matter
A file connector returns a table, but it does not always know which row holds the column names or what kind of values each column contains. If headers are wrong, every later step refers to columns named Column1, Column2 and so on. If data types are wrong, dates sort as text, amounts cannot be summed, and relationships between tables can fail.
Power BI Desktop usually guesses both. The guess is correct often enough that errors go unnoticed until a refresh breaks or a visual shows odd totals. Knowing exactly what each step does lets you check the guess and fix it.
Promoting headers
Promoting headers means using the values in the first row of a table as the column names. The M function is Table.PromoteHeaders.
How much work you need to do depends on the connector:
| Source | Header behavior |
|---|---|
| Excel table | Headers come from the table definition. No promotion is needed. |
| Excel sheet or named range | The first row is data until you promote it, unless the connector option `useHeaders` is `true`. |
| Text/CSV | `Csv.Document` returns generic names. Desktop adds a promote step, and you can add one yourself. |
The CSV example shows the promotion step:
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 tells Power Query to convert header values that are not text, such as numbers or dates, into text and use them as names. Without it, a header cell holding a number can be left as a generic column name. The option is worth including whenever a file might have a numeric header such as a year.
Headers that are not in the first row
Some exports start with a title, a blank line, or a report date before the real header row. If you promote the first row, the title becomes a column name and the true headers stay as data. Fix this in order:
- Use Remove Rows > Remove Top Rows to delete the lines above the header.
- Use Use First Row as Headers to promote the row that is now at the top.
- Check that no leftover blank rows remain below the header.
Order matters. If you promote before you remove rows, the later removal deletes the wrong rows.
Duplicate and blank headers
Power Query requires unique column names. If two header cells hold the same text, it appends a suffix, so a second Amount becomes Amount.1. A blank header cell becomes a name such as Column3. Rename these columns before you continue, because the generated names change if the source layout changes.
Setting column data types
A data type tells Power Query how to interpret the values in a column. The types you will use most often are in this table:
| Type | M expression | Use for |
|---|---|---|
| Whole number | `Int64.Type` | Counts, IDs stored as numbers |
| Decimal number | `type number` | Amounts, measurements |
| Fixed decimal number | `Currency.Type` | Money values that must not accumulate rounding error |
| Date | `type date` | Calendar dates without a time |
| Date/Time | `type datetime` | Timestamps |
| Text | `type text` | Names, codes, IDs with leading zeros |
| True/False | `type logical` | Flags |
The Excel example sets two types on a table named Sales:
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
TypedTable.TransformColumnTypes takes the table and a list of pairs. Each pair is a column name and a type. Columns that you do not list keep their current type.
Automatic type detection
Power BI Desktop can detect types for you. The setting is under File > Options and settings > Options > Current File > Data Load > Type Detection, and a global default sits under Global > Data Load. Detection samples the first rows of the source, and for unstructured sources such as CSV it applies a type from that sample. If row 5,000 holds a value that does not match the sampled type, the detected type is wrong and you see an error at refresh.
For this reason, many teams turn off automatic detection for files they control and set types explicitly. A deliberate Changed Type step documents what you expect the file to contain.
Type or locale
A date such as 03/04/2026 means March 4 in the United States and April 3 in much of Europe. Power Query converts text to a date using the locale of your machine unless you say otherwise. A report that works on your laptop can then give different results on a colleague's computer or in the service.
To fix the interpretation, use Change Type > Using Locale. This produces a call with a culture argument:
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, {{"OrderDate", type date}}, "en-GB")
in
TypedHere "en-GB" says the text uses day-first dates. Use a locale whenever the file's format differs from your own, and whenever decimals use a comma rather than a point.
Basic cleaning that goes with types
Type changes often fail because of dirty values. These steps usually come first:
- Trim removes leading and trailing spaces from text. A value such as
"42 "cannot convert to a number. - Clean removes non-printing characters that come from some exports.
- Replace Values converts markers such as
N/Aor-intonullbefore you change the type. - Remove Rows > Remove Blank Rows drops empty lines, which often appear at the bottom of a CSV file.
Put cleaning steps before the type change. A type change on a column that still holds N/A produces an error value in every such row.
Handling conversion errors
When a value cannot be converted, Power Query stores an error in the cell instead of stopping. The table loads, but the error cell shows Error, and the refresh in Power BI Desktop may report the rows as failed.
You have three options:
- Fix the source value.
- Clean the column before you convert it, for example with Replace Values.
- Use Replace Errors or Remove Errors, only when you know the lost values do not matter.
Check View > Column quality and Column profiling based on entire data set to find errors. By default, profiling uses only the first 1,000 rows, so errors further down stay hidden.
Common mistakes
- Typing before promoting. If you convert types while columns are still
Column1, the step stores those names. After you promote headers, the earlier step fails with a missing column error. - Relying on position. A promoted header followed by a type change refers to columns by name. If the source renames a column, the step breaks at refresh with
The column 'X' of the table wasn't found. - Storing IDs as numbers. Codes such as
00123lose leading zeros as numbers. Use text for identifiers that you do not do arithmetic on. - Using Decimal for money. Decimal number is a floating-point type. Fixed decimal keeps four decimal places and avoids small rounding differences in sums.
- Leaving the type as Any. A column of type Any has no type. It shows as
ABC123and can behave unpredictably in the model, so set a type on every column you load.
Making type steps resilient
If the source columns may change, you can avoid failures by building the type list from the columns that exist. This example sets every column to text except the two you name, and it does not fail when optional columns are missing:
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}}, "en-US")
in
TypedThe columns you do not list remain as they are. For columns that might be absent, pass MissingField.Ignore to functions such as Table.SelectColumns, so a missing column does not stop the refresh.
Checking your work
After you set headers and types, check three things before you close the editor:
- Every column shows a type icon, and none shows
ABC123. - Column quality shows 0% errors for key columns.
- The data preview matches the source file for the first and last rows.
Exercise
A CSV file begins with two lines of report title text, then a header row with OrderID, OrderDate, and Amount. You promote headers first and then remove the top two rows. What goes wrong, and what is the correct order?
Show answer
Promoting first makes the first title line the column names, and removing the top two rows then deletes the real header row and the first line of data. The correct order is to remove the top rows first, so the real header row is at the top, and then promote headers.
Exercise
A text column holds the value "N/A" in some rows. You change the column to Whole Number and see Error in those rows. Name two ways to fix it.
Show answer
Run Replace Values to turn "N/A" into null before the type change, or run Replace Errors after the type change, but only if the lost values do not matter. Fixing the source file also works.
Exercise
A report shows 4 March for a source value of 03/04/2026 on a colleague's computer but 3 April on yours. How do you make the result the same everywhere?
Show answer
Use Change Type with Locale, or pass a culture such as "en-GB" to Table.TransformColumnTypes, so the text is always interpreted with the same date format regardless of the machine's regional settings.