Numeric and text types
Choose a type by meaning, not appearance
A data type defines which values a column can contain and which operations make sense. A product code such as 0012 identifies an item, not an amount. Keep it as text. Quantities normally use Whole Number (Int64.Type); measurements often use Decimal Number (binary floating point in Power BI); money with at most four fractional digits can use Fixed Decimal Number (Currency.Type). A fixed decimal value does not store a currency code. Store units or currency separately and never sum amounts in different currencies without an explicit conversion policy. A format such as two displayed decimal places is not a conversion of the underlying type.
Example 1: preserve leading zeros when assigning types
Create a blank query in an approved disposable Desktop environment; replace its Advanced Editor expression with this self-contained M snippet. No connector is required. The source already contains text, so automatic CSV type inference cannot erase the identifiers.
let Source = #table(type table [ProductCode = text, Units = text, PriceUSD = text], {{"0012", "2", "12.50"}, {"0120", "3", "4.25"}}), Typed = Table.TransformColumnTypes(Source, {{"Units", Int64.Type}, {"PriceUSD", Currency.Type}}, "en-US"), WithRevenue = Table.AddColumn(Typed, "RevenueUSD", each [Units] * [PriceUSD], Currency.Type)in WithRevenueExpected: codes remain 0012 and 0120, quantities become 2 and 3, and revenue values are 25.00 and 12.75 USD, totaling 37.75 USD. The values fit the fixed decimal scale and range. The column type is declared explicitly; no claim is made that every intermediate arithmetic operation is exact for arbitrary input.
Example 2: decide precision before converting
For a USD rate of 0.123456 per unit, fixed decimal conversion with explicit nearest rounding to four places yields 0.1235; multiplying that by 10,000 yields 1,235 USD rather than 1,234.56 USD from the original decimal rate. The 0.44 USD difference is due to rounding before multiplication. In contrast, binary floating-point values are approximate and may surprise exact-equality comparisons. Define the required precision, when to round, and a comparison tolerance where appropriate. The small worked calculation uses decimal arithmetic, not observed M engine output. Do not assume that switching all prices to Currency.Type fixes every numerical problem.
Types at the Power Query and model boundary
M supports text, number, logical (true/false), date, time, datetime, datetimezone, duration and binary values among others. Its type system also includes structured values, such as records, lists and tables. A loaded Power BI model does not preserve all these distinctions: date/time/timezone loses its offset representation, duration loads as decimal number (expressed in days), and binary data must be converted to a supported representation before load. Date and time displays do not establish a separate storage representation in the model. Choose a model type explicitly after transformation; use True/False for Boolean values and text for identifiers. Avoid relying on the generic Any type for final query columns.
Common mistake: treating a display format as data recovery
If a CSV import automatically converts 0012 to 12, formatting it with four digits may make the visual look correct but does not recover arbitrary original identifiers. 12 and 0012 may be distinct codes. Remove or revise the automatic Changed Type step while the original text is still available; if not, reimport the raw file. Never reconstruct codes by guessing their width. Check nonintegral quantities before whole-number conversion because converting may round instead of rejecting them.
Practice: design a type contract
Use the first exercise in labs/data-types/worksheet.md. Assign types to product code, units, USD amount, temperature, business date, timestamp with offset, active flag and binary attachment. Reconcile the two revenue values and explain why the six-decimal rate needs a rounding policy.
Official reading
Power Query data types · Type conversion · Power BI model types · Currency.From. Documentation checked; native execution NOT RUN.