Type.OpenRecord is a Power Query M function that returns an opened version of a given record type, or the same type if it is already opened. The function returns the opened version of the input record type.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Type.OpenRecord( type as type ) as type
Type.OpenRecord function is designed to convert a closed record type into an open record type.It accepts a record type as input and, if the record is closed, returns an open version of it. If the input record is already open, the function simply returns the same open record type.
Let’s look at a few examples to learn how Type.OpenRecord works.
Transforming a Closed Record into an Open Record
Consider the following example where we have a closed record type:
type [ Date = date, Amount = number ]
To transform this closed record into an open record, you can use the
Type.OpenRecord function as follows:
// Output: type [ Date = date, Amount = number, ... ] Type.OpenRecord( type [ Date = date, Amount = number ] )
This expression effectively converts the initially closed record type into an open one, represented by the open-record-marker (
...) to indicate its new open nature.
Verifying the Transformation
To confirm whether the transformation from a closed record to an open record was successful, you can use the Type.IsOpenRecord function. This is demonstrated in the following code:
// Output: true let openRecord = Type.OpenRecord( type [ Date = date, Amount = number ] ), isOpenRecord = Type.IsOpenRecord( openRecord ) in isOpenRecord
Type.OpenRecord is first used to convert the record type, and then
Type.IsOpenRecord checks if the resulting record is indeed open, which, as shown, returns
Other functions related to Type.OpenRecord are: