<!-- https://learnsql.cpetoday.com/functions/m/type -->
# type

Language: Power Query M
Category: Language
Syntax: type typeExpression
Summary: Names a type, such as number, text or date, so you can tell Power Query what a value or column holds.
Returns: A type value, which Power Query uses in type steps and in function arguments.
Level: Intermediate
Related: Value.Is, Value.Type, Type.TableSchema, let, if

## What it does
The `type` keyword writes a type. You use it in a step that sets column types, such as Table.TransformColumnTypes, and as the third argument to Table.AddColumn, so that the new column is typed when it is created. Types also appear after `as` in a function's arguments. Setting types is a basic habit: it makes the query fail early when data is wrong, instead of later.

## Syntax and arguments
- `type number`, `type text`, `type date`, `type datetime`, `type logical`: the basic types.
- `type nullable number`: a number that can also be null. Columns with blanks usually need this.
- `type table [Name = text, Amount = number]`: a table type with named columns.

## Example
A bank export has text for the date and amount. The query sets the types once, near the end, so that the amounts add up and the dates sort.

```powerquery
let
    Source = Table.FromRecords({
        [Date = "2026-03-31", Amount = "1250", Memo = "Rent"],
        [Date = "2026-03-31", Amount = "480", Memo = "Supplies"]
    }),
    Typed = Table.TransformColumnTypes(Source, {
        {"Date", type date},
        {"Amount", type number}
    }),
    WithFlag = Table.AddColumn(Typed, "Large", each [Amount] >= 1000, type logical)
in
    WithFlag
```

After the type step, Amount is a number, so `List.Sum` and sorting work, and Date is a real date. The new Large column is typed as logical when it is created.

## Example: a second, different use
Declaring a function argument as optional and nullable: `(rate as nullable number) as number => rate ?? 1` accepts a null rate and uses 1 in its place.

## Things to watch
- A type step fails when a value does not convert. Clean the text first, or use try to set bad values aside.
- Set the types near the end of the query, after the cleanup steps.
- Use `nullable` for columns that can be blank. Without it, a null can cause an error.
- Type conversion follows the locale of the PC. For dates and decimals written in another style, pass a culture as the third argument of Table.TransformColumnTypes.

## In business terms
Typed columns are the difference between a total that works and one that quietly adds text. A type step is also a small piece of documentation: it states that the amount is a number and the date is a date.
