Type.ClosedRecord

Type

Returns a closed version of a record type, disallowing fields beyond those declared in the type.

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

Syntax

Type.ClosedRecord(type as type) as type

Parameters

NameTypeRequiredDescription
typetypeYesA record type to close. Must be a record type.

Return Value

typeA closed record type derived from the given record type.

Remarks

Type.ClosedRecord converts a record type into a closed record type. In Power Query M's type system, record types are either open or closed:

- An open record type permits values to have fields beyond those declared in the type. The base type record is open. - A closed record type requires values to have exactly the declared fields — no additional fields are allowed.

Type.ClosedRecord returns the closed version of whatever record type is passed in. If the type is already closed, it is returned unchanged. The declared field names and field types are preserved — only the open/closed flag changes. The complement of this function is Type.OpenRecord.

Closed record types are important in custom connector development and schema enforcement scenarios. When a type is closed, the M engine and tooling know the record's structure is fully specified, which can enable optimizations and stricter validation. Use Type.IsOpenRecord to test whether a type is open or closed before converting.

Examples

Example 1: Close the base record type and verify

let
    Closed = Type.ClosedRecord(type record)
in
    Type.IsOpenRecord(Closed)
Result
Result
1FALSE

Example 2: Close a typed record with declared fields

let
    Open = Type.ForRecord([Name = [Type = type text, Optional = false]], true),
    Closed = Type.ClosedRecord(Open)
in
    Type.IsOpenRecord(Closed)
Applied Steps

The final output — converts the open record type to a closed record type using Type.ClosedRecord, then checks Type.IsOpenRecord to confirm it is no longer open.

Result
1FALSE

Example 3: Round-trip open → close → open preserves field declarations

let
    RT = Type.ForRecord([ID = [Type = type number, Optional = false]], false),
    Opened = Type.OpenRecord(RT),
    Closed = Type.ClosedRecord(Opened),
    Fields = Type.RecordFields(Closed)
in
    Fields[ID][Type]
Applied Steps

The final output — retrieves the field descriptors from the closed type using Type.RecordFields, then reads the Type of the ID field to confirm it is type number.

Result
1type number

Compatibility

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