Table.RemoveColumns Function in Power Query M

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The Table.RemoveColumns function in Power Query removes the columns you name from a table and keeps everything else. It’s the step Power Query writes for you every time you right-click a column and choose Remove.

In this article, I’ll show you how to use it with practical examples, from removing one column to removing columns based on their position, names, or contents.

Follow along with the example file

Table.RemoveColumns Function Examples.xlsx

Download

Table.RemoveColumns Function Syntax

= Table.RemoveColumns(table as table, columns as any, optional missingField as nullable number) as table
  • table – the table you want to remove columns from. This is usually the previous step, such as Source.
  • columns – the column names you want to remove, as a list in curly brackets, such as {"Email","Phone"}. For a single column, you can also give just the name as text. Column names are case-sensitive.
  • missingField (optional) – what to do when a column you listed doesn’t exist in the table. By default (MissingField.Error), you get an error. MissingField.Ignore skips the missing column instead.

What it returns – the same table without the columns you listed. The remaining columns keep their order, and all the rows stay as they are.

The Table.RemoveColumns function works in Power Query in Excel for Microsoft 365, 2024, 2021, 2019, 2016, and Excel for Mac (Microsoft 365), as well as in Power BI.

When to Use the Table.RemoveColumns Function

Use this function when you need to:

  • Remove one or two columns you don’t need, like phone numbers or internal IDs
  • Drop columns that hold private data before you share a report
  • Remove a column that’s only there in some versions of a file, without breaking the query
  • Remove the first or last few columns when their names keep changing
  • Clean up the extra “Column4”, “Column5” headers that come with messy imports
  • Remove columns that are completely empty

Example 1: Remove a Single Column

Let’s start with the simplest use, removing one column from a table.

Below is a list of job applicants with their position, phone number, and status, and I want to remove the Phone column.

Job applicants table with Applicant, Position, Phone and Status columns

To follow along, select any cell in the table and go to Data > From Table/Range to open it in the Power Query Editor. If Power Query adds a Changed Type step, use #"Changed Type" in place of Source in the formulas below.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.RemoveColumns(Source,"Phone")

Result: a table with the Applicant, Position, and Status columns

Applicant, Position and Status columns; Phone is removed

Here, the formula takes the Source table and removes the column named “Phone”. The other three columns stay in the same order, and all six rows are still there.

Since there’s only one column, I gave the name as plain text. Writing it as a list, {"Phone"}, gives the same result.

You can also do this without typing. Right-click the Phone header and choose Remove, and Power Query adds a step called Removed Columns that uses this same function, with the name written as a list, {"Phone"}.

Table.RemoveColumns only works on columns. To remove rows that meet a condition, use the Table.SelectRows function to keep only the rows you want.

Example 2: Remove Multiple Columns

Most of the time, you’ll want to remove more than one column.

Below is a gym membership list with six columns, and I want to remove the Email and Locker No columns.

Gym membership table with Member ID, Member, Plan, Email, Locker No and Join Fee

Load this table into Power Query the same way as in Example 1, then add a new step (by clicking on the fx icon) and use this formula:

= Table.RemoveColumns(Source,{"Email","Locker No"})

Result: a table with the Member ID, Member, Plan, and Join Fee columns

Member ID, Member, Plan and Join Fee; Email and Locker No are removed

Here, the column names go inside curly brackets, separated by commas. That’s a list in Power Query, and Table.RemoveColumns removes every column in it.

The order of the names in the list doesn’t matter. {"Locker No","Email"} gives exactly the same table.

Each name can appear in the list only once, though. If you list the same column twice, like {"Email","Email"}, you get an error that says “The field ‘Email’ already exists in the record.”

Pro Tip: If your source might gain new columns later, removing the columns you don’t want lets those new columns into your query. To keep a fixed set instead, select the columns you want, right-click, and choose Remove Other Columns, which writes the Table.SelectColumns function.

Example 3: Remove a Column That Might Not Exist (MissingField.Ignore)

By default, Table.RemoveColumns gives an error when a column you listed isn’t in the table. The third argument lets you change that.

Below is a weekly timesheet export, and I want to remove the Entered By column, plus a Comments column that some weeks’ exports have and this one doesn’t.

Weekly timesheet with Employee, Project, Week, Hours and Entered By, and no Comments column

If you use Table.RemoveColumns(Source,{"Entered By","Comments"}) here, the step fails with this message: “Expression.Error: The column ‘Comments’ of the table wasn’t found.”

The whole step fails, so even the Entered By column, which does exist, isn’t removed. You get the same error when the capitalization doesn’t match, because asking for “entered by” when the column is “Entered By” fails too.

Load this table into Power Query the same way as in Example 1, then add a new step (by clicking on the fx icon) and use this formula:

= Table.RemoveColumns(Source,{"Entered By","Comments"},MissingField.Ignore)

Result: a table with the Employee, Project, Week, and Hours columns

Employee, Project, Week and Hours; Entered By removed and the missing Comments skipped

Here, MissingField.Ignore tells the function to skip any column it can’t find. Entered By is removed, Comments is skipped, and no error shows up.

This helps a lot when the same query runs on a new file every week. When a file does have the Comments column, the query removes it, and when it doesn’t, the query still runs.

You may also see MissingField.UseNull as the third argument. In functions that keep columns, like Table.SelectColumns, it adds the missing column filled with null.

With Table.RemoveColumns, UseNull works the same as Ignore. The missing column is skipped, nothing is added, and no error shows up.

Just remember that Ignore also hides typos. If you type “Entred By”, the query runs without an error but the column stays, so check that the result is missing the columns you listed.

Example 4: Remove the First Column (By Position)

Sometimes you know which column to remove by where it sits, not by its name.

Below is a product sales export where the first column is a row number, and its header changes from one export to the next (“#”, “Row No”, “Sr”). I want to remove that first column whatever it’s called.

Product sales export whose first column is a # row number

Load this table into Power Query the same way as in Example 1, then add a new step (by clicking on the fx icon) and use this formula:

= Table.RemoveColumns(Source,Table.ColumnNames(Source){0})

Result: a table with the Product, Category, and Units Sold columns

Product, Category and Units Sold; the first column is removed

Here, the Table.ColumnNames function gives a list of all the column names in the table. Then {0} picks the first item from that list, because Power Query counts positions from 0.

So Table.ColumnNames(Source){0} returns “#” in this table, and Table.RemoveColumns removes it. If the next export calls it “Row No”, the same formula removes that column instead.

This relies on the column order, though. If a new export ever puts another column first, the formula removes that one, so use it only when the first column is always the one you don’t need.

Example 5: Remove the Last Two Columns

This next one works the same way, but from the other end of the table.

Below is an invoice export where the last two columns are added by the billing system (here, Created By and Source System), and their names vary between versions. I want to remove those last two columns.

Invoice export ending with Created By and Source System columns

Load this table into Power Query the same way as in Example 1, then add a new step (by clicking on the fx icon) and use this formula:

= Table.RemoveColumns(Source,List.LastN(Table.ColumnNames(Source),2))

Result: a table with the Invoice No, Customer, and Amount columns

Invoice No, Customer and Amount; the last two columns are removed

Here, Table.ColumnNames gives the list of all five column names, and the List.LastN function takes the last 2 names from it. That’s {"Created By","Source System"}, and Table.RemoveColumns removes both.

To remove the first few columns instead, use the List.FirstN function in the same place. For example, List.FirstN(Table.ColumnNames(Source),2) returns the names of the first two columns.

Example 6: Remove Columns Whose Names Match a Pattern

When Power Query promotes the first row to headers and a header cell is empty, it names that column by its position, like Column4 or Column5. You can find all such columns by their names instead of typing each one.

Below is a course schedule with two such columns that hold only a few stray notes, and I want to remove every column whose name starts with “Column”, notes and all.

Course schedule with extra Column4 and Column5 holding stray notes

This query has more than one step, so it goes in the Advanced Editor. Go to Data > Get Data > From Other Sources > Blank Query, then open the Advanced Editor (Home > Advanced Editor) and use this code.

The course schedule table is named CourseSchedule, and the Source line reads it by that name, so you don’t have to load it into Power Query first.

let
Source = Excel.CurrentWorkbook(){[Name="CourseSchedule"]}[Content],
ExtraColumns = List.Select(Table.ColumnNames(Source),each Text.StartsWith(_,"Column")),
#"Removed Columns" = Table.RemoveColumns(Source,ExtraColumns)
in
#"Removed Columns"

Result: a table with the Course, Instructor, and Seats columns

Course, Instructor and Seats; Column4 and Column5 are removed

Here, the ExtraColumns step uses the List.Select function to go through all the column names and keep only the ones that start with “Column” (the underscore _ stands for each name as it’s checked). That gives {"Column4","Column5"}.

The last step then removes those columns. If the next import has a Column6 as well, the query removes it too, without any change to the code.

The Text.StartsWith function is case-sensitive, so “column4” wouldn’t match. And it matches any name that starts with “Column”, so a real column called “Column Notes” would be removed as well.

Example 7: Remove Columns That Are Completely Empty

Exports from other systems often come with columns that have a header but no data.

Below is a supplier contact list where the Fax and Website columns are empty, and I want to remove every column that has no values at all.

Supplier contacts where the Fax and Website columns are completely empty

The supplier table is named Suppliers. Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Suppliers"]}[Content],
EmptyColumns = List.Select(Table.ColumnNames(Source),each List.NonNullCount(Table.Column(Source,_))=0),
#"Removed Columns" = Table.RemoveColumns(Source,EmptyColumns)
in
#"Removed Columns"

Result: a table with the Supplier, Contact, Phone, and City columns

Supplier, Contact, Phone and City; the empty Fax and Website columns are removed

Here, the Table.Column function gets all the values in one column, and the List.NonNullCount function counts how many of them aren’t null. The List.Select function keeps the names of the columns where that count is 0.

Fax and Website have no values, so they end up in the EmptyColumns list and get removed. If a supplier adds a fax number later, the Fax column stays on the next refresh.

This checks for null, which is what blank cells from an Excel table come in as. A column filled with empty text (“”) or spaces still counts as having values, so it isn’t removed.

Follow along with the example file

Table.RemoveColumns Function Examples.xlsx

Download

Example 8: Remove Columns Listed in Your Worksheet

This last one is handy when you share a report and the list of columns to hide changes from time to time.

Below is a customer list that includes email addresses and credit limits, and I want to remove the columns listed in a separate table before I share it.

Customer list with Customer, City, Segment, Email and Credit Limit

The columns to remove are listed in a one-column table called ColumnsToRemove, on its own sheet (Example 8 Columns). Right now, it lists Email and Credit Limit.

Create a new blank query, open the Advanced Editor, and use this code. It reads both tables by name, so you don’t have to load them into Power Query first.

let
Source = Excel.CurrentWorkbook(){[Name="Customers"]}[Content],
RemoveList = Excel.CurrentWorkbook(){[Name="ColumnsToRemove"]}[Content][Columns to Remove],
#"Removed Columns" = Table.RemoveColumns(Source,RemoveList)
in
#"Removed Columns"

Result: a table with the Customer, City, and Segment columns

Customer, City and Segment; Email and Credit Limit from the list are removed

Here, the RemoveList step reads the Columns to Remove column of the ColumnsToRemove table. Taking one column from a table this way gives you a list, {"Email","Credit Limit"}, which is exactly what Table.RemoveColumns needs.

Add a column name to the ColumnsToRemove table (or delete one) and refresh the query, and the result changes with it. You never have to open the M code.

Important: Each name in the ColumnsToRemove table has to match a column name exactly, and the list can’t have blank cells or repeated names. Any of these makes the refresh fail, so fix the table and refresh again.

Other Excel Articles You May Also Like:

All Power Query Functions

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.