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., [Precision = 10, Scale = 2]).

Return Value

typeA 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, Precision and Scale for numeric types, or MaxLength for text types.

The facets record only needs to include the fields you want to set. Any facets not mentioned in the record retain their values from the source type. To inspect the current facets of a type before replacing them, 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 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, [Precision = 10, Scale = 2])
in
    Type.Facets(Constrained)
Applied Steps

The final output — applies Precision = 10 and Scale = 2 facets to the number type using Type.ReplaceFacets, then calls Type.Facets to inspect the resulting facet values.

Name
Value
1Precision10
2Scale2

Example 2: Set MaxLength on a text type

let
    T = Type.ReplaceFacets(type text, [MaxLength = 100])
in
    Type.Facets(T)
Result
Name
Value
1MaxLength100

Example 3: Clear a facet by setting it to null

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

The final output — removes both facets by setting them to null with another call to Type.ReplaceFacets, then calls Type.Facets to confirm the facet values are now null.

Name
Value
1Precisionnull
2Scalenull

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks