OpenBI Docs Buy

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
ParameterTypeDescription
valueanyThe value, usually a table.
typetypeThe 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])
ItemPrice
Chair50

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]]
NameTypeName
ProductText.Type
PriceCurrency.Type

Value.Type, Table.TransformColumnTypes, Table.RenameColumns, Table.Schema.

Last updated · OpenBI Studio 0.3.79