Record.RemoveFields Function (Power Query M)

If you want to drop a few fields from a record, and keep everything else, the Record.RemoveFields function is what you reach for. It returns a new record with the fields you name taken out, leaving the rest in their original order. Available in Excel (Power Query), Power BI Desktop, and Power BI Service.

Syntax of Record.RemoveFields Function

Record.RemoveFields(record as record, fields as any, optional missingField as nullable number) as record

where

  • record (required, record). The source record you want to drop fields from.
  • fields (required, any). The field names to remove, given as a list like {"City","Phone"}. A single name as plain text also works. The fields you do not name stay in their original order.
  • missingField (optional, nullable number). Controls what happens when you name a field that the record does not have. Leave it out and a missing name raises an error. Pass MissingField.Ignore to skip the absent name silently instead.

Returns: a new record containing every field except the ones you named, in their original order. The original record is left unchanged.

In plain terms, you hand it a record and a list of field names, and it gives you back the same record with those fields stripped out.

Example 1: Remove one field from a record

Say you have a person record with three fields and you want to drop the Age field.

let
Source = Record.RemoveFields([Name="Ava",City="Pune",Age=29],"Age")
in
Source

Result: [Name = "Ava", City = "Pune"]

The Age field is removed, and Name and City stay exactly where they were. For a single field you can pass the name as plain text, with no list needed.

Example 2: Remove multiple fields with a list

To drop more than one field, pass the names as a list instead of a single text value.

Here you have an employee record and want to strip out the City and Phone fields.

let
Source = Record.RemoveFields([Name="Liam",Dept="Sales",City="Austin",Phone="555-0140"],{"City","Phone"})
in
Source

Result: [Name = "Liam", Dept = "Sales"]

Both named fields are gone, and the survivors Name and Dept keep their original order.

Example 3: Handle a field that is not in the record

Naming a field the record does not have throws an error by default. Pass MissingField.Ignore to skip the absent name instead.

This record has Product, Price, and Stock, but you ask to remove Discount, which is not there.

let
Source = Record.RemoveFields([Product="Mug",Price=12,Stock=40],"Discount")
in
Source

Result: Expression.Error: The field 'Discount' of the record wasn't found.

Add MissingField.Ignore as a third argument and the call stops erroring. Here you ask to remove both Discount (missing) and Stock (present):

let
Source = Record.RemoveFields([Product="Mug",Price=12,Stock=40],{"Discount","Stock"},MissingField.Ignore)
in
Source

Result: [Product = "Mug", Price = 12]

The missing Discount is skipped quietly, Stock is removed, and you get back the two fields that are left.

Example 4: Drop a field from every row of a table

Record.RemoveFields works on a single record, so to use it across a table you run it per row with Table.TransformRows, then turn the records back into a table with Table.FromRecords.

Here is the starting data, with an Internal column you want gone:

OrderIDCustomerInternal
1001Avaflag-a
1002Liamflag-b
1003Noahflag-c

Remove the Internal field from each row:

let
Source = Excel.CurrentWorkbook(){[Name="Orders"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"OrderID",Int64.Type},{"Customer",type text},{"Internal",type text}}),
Cleaned = Table.FromRecords(Table.TransformRows(Typed,each Record.RemoveFields(_,"Internal")))
in
Cleaned

Each row is a record, so Record.RemoveFields drops the Internal field from every one.

The result keeps just the two columns:

OrderIDCustomer
1001Ava
1002Liam
1003Noah

Table.TransformRows runs your function once per row, much like List.Transform does for a list.

Example 5: For a whole table, use Table.RemoveColumns

If you are working on a full table rather than a single record, you do not need the per-row trick. Table.SelectColumns and its sibling Table.RemoveColumns are the table-level tools. Table.RemoveColumns drops the columns you name directly.

Here is the starting data:

OrderIDCustomerInternal
1001Avaflag-a
1002Liamflag-b
1003Noahflag-c

Drop the Internal column directly:

let
Source = Excel.CurrentWorkbook(){[Name="Orders"]}[Content],
Dropped = Table.RemoveColumns(Source,{"Internal"})
in
Dropped

The result has only the two remaining columns:

OrderIDCustomer
1001Ava
1002Liam
1003Noah

This is the cleaner choice when your data is already a table. Reach for Record.RemoveFields when you are inside a record, for example a single row pulled out with Table.TransformRows.

Things to keep in mind with Record.RemoveFields

  • fields takes a single name or a list. A lone field is fine as plain text ("Age"), and {"Age"} does the same thing. Use the list form when you have more than one.
  • Field names are case-sensitive. "age" will not match a field called Age, so it counts as a missing name and triggers the error below.
  • A missing field throws by default. Naming a field the record does not have raises Expression.Error: The field 'X' of the record wasn't found. Pass MissingField.Ignore as the third argument to skip absent names silently.
  • Surviving fields keep their original order. Unlike Record.SelectFields, which reorders to match your list, Record.RemoveFields leaves the remaining fields exactly where they were.
  • It is the inverse of Record.SelectFields. This names what to drop, while Record.SelectFields names what to keep. Pick whichever needs the shorter list.
  • To read a single value, use Record.Field instead. Record.RemoveFields always returns a record, so use Record.Field when you want the bare value of one field rather than a trimmed-down record.
  • For a whole table, use Table.RemoveColumns. It drops columns directly, no per-row record handling needed.

Common questions about Record.RemoveFields

How is Record.RemoveFields different from Record.SelectFields?

They are opposites. Record.RemoveFields keeps everything except the fields you name, while Record.SelectFields keeps only the fields you name. Use whichever leaves you with the shorter list to write.

What is the difference between Record.RemoveFields and Table.RemoveColumns?

Record.RemoveFields works on one record at a time, while Table.RemoveColumns drops columns from an entire table at once. Use the record version when you are inside a single row, and the table version for the whole dataset.

List of All Power Query Functions

Related Power Query Functions / Articles:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.