Type.ReplaceFacets

Type

Returns a new type with the specified facets replaced, allowing customization of type constraints such as precision and scale.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Type.ReplaceFacets(type as type, facets as record) as type

Parameters

NameTypeRequiredDescription
typetypeYesThe base type whose facets are replaced.
facetsrecordYesA record specifying the facet values to set (e.g., [NumericPrecision = 10, NumericScale = 2]).

Return Value

type — A new type with the provided facets applied.

Remarks

Type.ReplaceFacets returns a new type value that is identical to the input type except that the facets specified in the facets record are replaced with the provided values. Facets are type constraint properties beyond the base kind — for example, NumericPrecision and NumericScale for numeric types, or MaxLength and IsVariableLength for text types. The facet names are the nine fields returned by Type.Facets.

The facets record lists the facets to set, using the same field names that Type.Facets returns. To inspect a type's current facets, use Type.Facets.

Type.ReplaceFacets is most useful in custom connector development, where you need to construct M type values that carry database-level schema constraints (such as DECIMAL(10, 2) precision or NVARCHAR(50) length from a SQL source). It is the write-side counterpart to the read-side Type.Facets. The resulting type can be applied to a value with Value.ReplaceType.

Note that setting facets does not validate or constrain actual data values at runtime — M's type system uses facets as metadata, not as enforcement mechanisms during evaluation.

Examples

Example 1: Set precision and scale on a number type

let
    BaseType = type number,
    Constrained = Type.ReplaceFacets(BaseType, [NumericPrecision = 10, NumericScale = 2])
in
    Type.Facets(Constrained)
Applied Steps

The final output — Type.Facets shows NumericPrecision 10 and NumericScale 2, with every other facet null.

Name
Value
1NumericPrecisionBasenull
2NumericPrecision10
3NumericScale2
4DateTimePrecisionnull
5MaxLengthnull
6IsVariableLengthnull
7NativeTypeNamenull
8NativeDefaultExpressionnull
9NativeExpressionnull

Example 2: Describe a SQL nvarchar(50) column on a text type

let
    T = Type.ReplaceFacets(type text, [MaxLength = 50, IsVariableLength = true, NativeTypeName = "nvarchar"])
in
    Type.Facets(T)
Applied Steps

The final output — Type.Facets reads the facets of T: MaxLength 50, IsVariableLength true, NativeTypeName "nvarchar", and the rest null.

Name
Value
1NumericPrecisionBasenull
2NumericPrecisionnull
3NumericScalenull
4DateTimePrecisionnull
5MaxLength50
6IsVariableLengthtrue
7NativeTypeNamenvarchar
8NativeDefaultExpressionnull
9NativeExpressionnull

Example 3: Clear facets by setting them to null

let
    Constrained = Type.ReplaceFacets(type number, [NumericPrecision = 10, NumericScale = 2]),
    Cleared = Type.ReplaceFacets(Constrained, [NumericPrecision = null, NumericScale = null])
in
    Type.Facets(Cleared)
Applied Steps

The final output — Type.Facets confirms every facet is null again.

Name
Value
1NumericPrecisionBasenull
2NumericPrecisionnull
3NumericScalenull
4DateTimePrecisionnull
5MaxLengthnull
6IsVariableLengthnull
7NativeTypeNamenull
8NativeDefaultExpressionnull
9NativeExpressionnull

Compatibility

✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks
Contributors
kyleamueller