Value.ReplaceType
ValueReplaces the type metadata of a value without converting the value itself.
Syntax
Value.ReplaceType(value as any, type as type) as anyParameters
| Name | Type | Required | Description |
|---|---|---|---|
value | any | Yes | The value whose type metadata to replace. |
type | type | Yes | The new type to assign. This replaces the metadata but does not convert the value. |
Return Value
any — The original value with its type metadata replaced by the specified type.
Remarks
Value.ReplaceType replaces the type metadata attached to a value without performing any conversion. The underlying data remains unchanged — only the type annotation is updated. This is commonly used to:
- Assign a custom record type with field-level documentation to a record or table row. - Attach function type metadata (parameter names, descriptions) to custom functions. - Override the inferred type of a table to provide more specific column type information.
Important: This does not convert or validate the value. If you assign an incompatible type, the value may cause errors downstream when the type is checked.
Examples
Example 1: Assign a custom record type to a Sales row
let
FirstRow = Table.First(Table.SelectColumns(Table.FirstN(Sales, 1), {"CustomerName", "Product", "Region"})),
CustomType = type [CustomerName = text, Product = text, Region = text],
Typed = Value.ReplaceType(FirstRow, CustomType),
IsMatch = Value.Is(Typed, CustomType)
in
#table(
{"CustomerName", "Product", "Region", "TypeAssigned"},
{{Typed[CustomerName], Typed[Product], Typed[Region], Text.From(IsMatch)}}
)CustomerName | Product | Region | TypeAssigned | |
|---|---|---|---|---|
| 1 | Alice | Widget A | East | true |