Record.SelectFields

Updated on

Record.SelectFields is a Power Query M function that filters a record to include only the specified fields. The function returns a new record containing only the fields specified in the input list.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Record.SelectFields(
   record as record,
   fields as any,
   optional missingField as nullable number,
) as record
Argument Attribute Description
record
fields
missingField optional The MissingField.Type determines the function’s reaction to operations on missing columns. When omitted, it uses MissingField.Error and generates an error for missing columns. Alternatives include MissingField.UseNull, substituting null for missing columns, and MissingField.Ignore, which ignores missing columns.

Description

Record.SelectFields filters a record, returning only the fields listed in fields. This function helps in isolating specific data points within a record. In case a specified field does not exist, the function returns an error by default. You can change this behavior by providing an optional MissingField.Type.

Examples

Select the fields “Item” and “Price” in the record.

// Output: [Item = "Fishing rod", Price = 100]
Record.SelectFields( 
    [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],
    {"Item", "Price"}
 )

Other functions related to Record.SelectFields are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/record-selectfields