Sub topic 9
Setting Data Types on the Combined Table
This chapter assumes you can open the Power Query editor, you have already combined a folder of files with Combine & Transform Data, and you know what the generated sample file query and function query do. Here you will set data types on the combined table, understand where in the query to do it, and avoid the errors that wrong types cause.
Why data types matter
Power Query gives every column a data type. The type decides how values are sorted, compared, summed and loaded into Excel. A column of dates stored as text sorts alphabetically, so "10/01/2026" lands before "2/01/2026". A column of amounts stored as text cannot be summed in a PivotTable. A date stored as text may also arrive in the worksheet left-aligned and unusable in a date filter.
Combined folders make this more important. The combine step reads each file separately and appends the results. If the files do not agree on types, the combined column can end up as text or hold errors.
The main types you will use are:
| Type | M name | Typical use |
|---|---|---|
| Text | `type text` | Names, codes, regions, IDs with leading zeros |
| Whole Number | `Int64.Type` | Counts, quantities |
| Decimal Number | `type number` | Amounts, rates |
| Fixed Decimal Number | `Currency.Type` | Money with exactly four decimals |
| Date | `type date` | Transaction dates |
| Date/Time | `type datetime` | Timestamps |
| True/False | `type logical` | Flags |
Automatic type detection
When you load a CSV file, Power Query often detects types for you and adds a step named Changed Type. This detection looks only at the first part of the data, by default the first 200 rows. A column whose first 200 rows hold whole numbers but whose later rows hold decimals can be typed wrongly.
You control this in the editor under File > Options and settings > Query Options. Under Current Workbook > Data Load, the Type Detection setting can be set to detect types per workbook, never detect, or follow the global setting. Many analysts choose Never detect column types and headers for unstructured sources for folder work. They then set types themselves, so the result does not change if the files change.
Where to set types: sample file or combined query
A combined-folder setup has two places where a type can be set, and they behave differently.
- Transform Sample File. A type set here applies to each file before the files are appended. It is the right place when each file needs the same fix, such as removing a currency symbol before converting to a number.
- The combined query. A type set here applies once, after all files are appended. This is the usual place for final types.
Setting types in the combined query is safer in most cases. Each file is first read as plain values, the files are appended, and the types are applied one time to the whole column. This avoids a conflict in which one file's Amount column was typed as a number and another's was typed as text.
Setting types in the editor
To set a type in the combined query:
- Open the combined query in the Power Query editor.
- Select the column, or select several columns with Ctrl.
- Choose Transform > Data Type and pick the type. You can also click the type icon at the left of the column heading.
- Check the Applied Steps pane. A new Changed Type step appears.
The step is plain M. For example:
= Table.TransformColumnTypes(Expanded, {{"Date", type date}, {"Region", type text}, {"Amount", type number}})Each pair in the list is a column name and a type. The step fails if a name in the list does not exist in the table, so a renamed column in a new file breaks the step.
Using a locale for dates and numbers
A value such as 03/04/2026 is 3 April in many countries and 4 March in the United States. A number such as 1.234,56 uses a comma as the decimal separator in much of Europe. Power Query converts text using the locale of your computer unless you tell it otherwise. If the files come from a system with a different locale, the same file can give different results on different computers.
Use Using Locale to avoid this:
- Right-click the column heading, or open the type icon menu.
- Choose Change Type > Using Locale.
- Pick the data type and the locale that matches the source files, for example English (United Kingdom) for day-first dates.
The generated step names the culture as a third argument:
= Table.TransformColumnTypes(Expanded, {{"Date", type date}}, "en-GB")With a fixed culture, the result is the same on every computer that refreshes the query.
Handling errors from type conversion
If a value cannot be converted, Power Query puts an Error in that cell. A common cause is a footer line such as Total in a column that should hold numbers. The query still loads, but the error cells appear as [Error] in the editor and are loaded as blank or error values depending on how you load.
To find them, select the column and look at the column quality bar under the heading, which shows the percentage of valid, error and empty values. You can also choose Home > Keep Rows > Keep Errors. Then do one of these:
- Fix the cause, for example filter out the footer rows before the type step.
- Use Remove Errors if dropping those rows is acceptable.
- Use Replace Errors to put a default value, such as 0 or null, in the cells.
Filter before you convert. A pattern that works well is to remove unwanted rows first, then change the type:
let
Source = Folder.Files("C:\Data\Sales"),
CsvOnly = Table.SelectRows(Source, each [Extension] = ".csv"),
Parsed = Table.AddColumn(CsvOnly, "Data", each Table.PromoteHeaders(Csv.Document([Content], [Delimiter = ",", Encoding = 65001]))),
Kept = Table.SelectColumns(Parsed, {"Name", "Data"}),
Expanded = Table.ExpandTableColumn(Kept, "Data", {"Date", "Region", "Amount"}),
NoTotals = Table.SelectRows(Expanded, each [Region] <> "Total"),
Typed = Table.TransformColumnTypes(NoTotals, {{"Date", type date}, {"Region", type text}, {"Amount", type number}})
in
TypedThe NoTotals step removes the footer rows before Typed tries to convert them.
Keep leading zeros by using text
Identifiers such as product codes 00123 or postal codes should be set to text. If Power Query detects them as whole numbers, the leading zeros are lost, and they do not come back when you change the type back to text. Set the type to text before any automatic detection runs on those columns, or turn off automatic detection as described earlier.
Types and refresh
The type step is part of the query, so it runs again on every refresh. This has two consequences.
First, if a later file contains a value that cannot be converted, the refresh does not fail. The affected cells become errors. Check the quality bar after you add new files.
Second, if a file arrives with a column renamed, the type step refers to a column that is missing, and the refresh fails with an error such as "The column 'Amount' of the table wasn't found." The next chapters on structure and troubleshooting cover that case. A defensive option is MissingField.Ignore:
= Table.TransformColumnTypes(Expanded, {{"Amount", type number}}, "en-GB")Table.TransformColumnTypes has no missing-field option, so to tolerate absent columns you can use Table.TransformColumns with MissingField.Ignore as the third argument:
= Table.TransformColumns(Expanded, {{"Amount", each try Number.From(_) otherwise null, type number}}, null, MissingField.Ignore)This version also turns unconvertible values into null instead of errors. Use it deliberately, because it hides bad data instead of reporting it.
Types and loading to Excel
The type chosen in Power Query controls how the column arrives in the worksheet. Date columns get a date format, number columns are right-aligned and can be summed, and text columns stay as text. A column left as Any type (shown with an ABC123 icon) can load with mixed formatting and should be avoided in the final query.
Sort out the last step before you choose Close & Load: every column in the final query should show a specific type icon.
Summary of the working model
- Types are applied by M steps, not by Excel formatting.
- Set final types in the combined query, and use the sample file query only for per-file fixes.
- Use Using Locale when dates or numbers come from a different region.
- Filter out unwanted rows before converting.
- Use text for identifiers.
- Check the column quality bar after each refresh with new files.
Exercise
A combined query loads sales files and the Amount column contains a footer row with the text "Total" in each file. After you set Amount to Decimal Number, some cells show Error. What are two ways to fix this, and which one is better here?
Show answer
You can either filter out the footer rows before the type step (for example with Table.SelectRows keeping rows where Region is not "Total"), or use Remove Errors or Replace Errors after the type step. Filtering first is better because it removes the cause and does not risk hiding other real conversion errors.
Exercise
Your files come from a UK system and contain dates such as 03/04/2026, meaning 3 April. A colleague in the United States refreshes the query and sees 4 March. Which feature prevents this, and how does it appear in the M code?
Show answer
Use Change Type > Using Locale with English (United Kingdom). The M step gets a culture argument, for example Table.TransformColumnTypes(Expanded, {{"Date", type date}}, "en-GB"), so every computer converts the text the same way.