Value.ReplaceType
Gives a value a new type without changing its contents; for a table, new column names and types.
Group: Values, types and errors. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Value.ReplaceType(value as any, type as type) as any
| Parameter | Type | Description |
|---|---|---|
value | any | The value, usually a table. |
type | type | The new type; for a table, a table type with as many columns. |
Returns
any. The same value carrying the new type.
Remarks
- Nothing is converted: the type is declared on the value as it is. To change the values themselves use
Table.TransformColumnTypes. - The new type must fit the kind of value: text given
type number, or a table given a table type with another number of columns, is an error. - A table's columns get the new type's names by position, which renames every column in one step.
Examples
Rename columns by position
let
Lines = #table({"Product", "Price"}, {{"Chair", 50}})
in
Value.ReplaceType(Lines, type table [Item = text, Price = number])
| Item | Price |
|---|---|
| Chair | 50 |
Declare column types
let
Lines = #table({"Product", "Price"}, {{"Chair", 50}}),
Typed = Value.ReplaceType(Lines, type table [Product = text, Price = Currency.Type])
in
Table.Schema(Typed)[[Name], [TypeName]]
| Name | TypeName |
|---|---|
| Product | Text.Type |
| Price | Currency.Type |
Related functions
Value.Type, Table.TransformColumnTypes, Table.RenameColumns, Table.Schema.