List.RemoveItems 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 List.RemoveItems function in Power Query takes a list and removes every value you tell it to. You give it two lists, and it returns the first one with every copy of the second list’s values taken out.

You’d use it to drop test entries from a signup list, skip the zeros before you average a column, or remove filler words from text.

Follow along with the example file

List.RemoveItems Function Examples.xlsx

Download

List.RemoveItems Function Syntax

List.RemoveItems(list1 as list, list2 as list) as list
  • list1 – the list you want to remove values from.
  • list2 – the values to remove. Every copy of each of these values is taken out of list1.

What it returns: A list with what’s left of list1, in its original order. If none of the values in list2 are in list1, you get list1 back unchanged.

The List.RemoveItems function is part of the Power Query M language, and Power Query is built into Excel 365, 2024, 2021, 2019, and 2016 for Windows. Excel for Microsoft 365 on Mac has Power Query too, but Excel 2016 and 2019 for Mac don’t.

When to Use the List.RemoveItems Function

Use this function when you need to:

  • Remove a few specific values from a list, wherever they show up
  • Remove the entries listed in another table, like test accounts or excluded items
  • Remove zeros or placeholder values before you calculate an average
  • Remove filler words from text
  • Remove holidays from a list of dates
  • Get all the column names of a table except a few

Example 1: Remove Values From a List

Let’s start with a simple one. Suppose you have the T-shirt sizes from this week’s orders, and you’ve stopped making XS and XL, so you want to see only the sizes you still sell.

In Excel, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor that opens, type this formula in the formula bar:

= List.RemoveItems({"M","L","XS","M","XL","S","XS","M"},{"XS","XL"})

Result: A list with M, L, M, S, and M

List.RemoveItems removes XS and XL, leaving M, L, M, S and M

Here, the first list has the sizes from the orders and the second list has the sizes to remove. List.RemoveItems takes out both XS orders and the XL order, and keeps everything else in the same order.

If the second list has a value that isn’t in the first list, List.RemoveItems ignores it. So adding “XXL” to the second list gives you the same result, with no error.

In the example file, Example 1 types its values right into the query, so it doesn’t have a sheet. You can open it from Data > Queries & Connections.

Example 2: Remove Every Copy of a Value

This is the part that makes List.RemoveItems different from the List.Difference function. Suppose you ran a quick poll, and you want only the clear answers, without any “Not sure” responses.

Create a new blank query (as in Example 1), open the Advanced Editor (Home > Advanced Editor), and use this code:

let
Answers = {"Yes","No","Not sure","Yes","Not sure","Yes","No"},
Result = List.RemoveItems(Answers,{"Not sure"})
in
Result

Result: A list with Yes, No, Yes, Yes, and No

Both Not sure answers are removed, leaving Yes, No, Yes, Yes and No

Here, “Not sure” is in the second list only once, but both “Not sure” answers are removed. List.RemoveItems takes out every copy of a value, no matter how many times it shows up in the first list.

The List.Difference function works differently. Each value in its second list takes out only one matching copy, so List.Difference(Answers,{"Not sure"}) leaves the second “Not sure” in the result.

So when you want a value gone completely, use List.RemoveItems. You can see both versions side by side in the example file.

Example 3: Remove the Entries Listed in Another Table

This one comes up a lot with real data. I have a table of newsletter signups, and some of them are test signups our team made while setting up the form.

Below is the signups table, named Signups, on the Example 3 Signups sheet.

Signups table with the signup date and email of each signup

And here is the table of test email addresses, named TestEmails, on the Example 3 Test Emails sheet.

TestEmails table with the two test email addresses

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Signups"]}[Content],
Tests = Excel.CurrentWorkbook(){[Name="TestEmails"]}[Content],
RealSignups = List.RemoveItems(Source[Email],Tests[Test Email])
in
RealSignups

Result: A list with marilyn.gibson@example.com, nolan.martin@example.com, audrey.hughes@example.com, daniel.kelly@example.com, and samuel.morgan@example.com

The five real signups, with every test email removed

Here, the Source step reads the signups table and the Tests step reads the test emails table. Source[Email] and Tests[Test Email] each give that column as a list, and List.RemoveItems takes the test emails out of the signups.

test@example.com was used three times, and all three are gone. That’s why List.RemoveItems is the right pick here, since the same test address often shows up again and again.

Keep in mind that the result is a list of emails, so the signup dates aren’t in it. If you need the full rows, filter the table with the Table.SelectRows function instead.

Since the test emails live in their own table, you can keep that list up to date. When someone uses a new test address, add it to the TestEmails table and click Refresh.

Example 4: Remove Zeros Before Taking an Average

Here’s one that can quietly throw your numbers off. Below is a table named CallLog with the length of each support call in minutes, where 0 means the call was missed, and I want the average length of the calls that were answered.

CallLog table with the minutes of each call, where 0 is a missed call

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="CallLog"]}[Content],
Answered = List.RemoveItems(Source[Minutes],{0}),
AvgMinutes = List.Average(Answered)
in
AvgMinutes

Result: 10.8

The average of the answered calls is 10.8 minutes

Here, the Answered step removes all three zeros from the Minutes column. The List.Average function then averages the five calls that are left, so you get 10.8 minutes.

If you averaged the column with the zeros in it, you’d get 6.75. That number is too low, because the missed calls aren’t really calls that lasted zero minutes.

Notice that the 0 in the second list has no quotes around it. List.RemoveItems only removes values of the same type, so {"0"} (zero as text) wouldn’t remove anything from a column of numbers.

You don’t need to remove blank cells for an average, since List.Average already skips them. If your column has blanks you want gone for some other reason, add null to the second list, like {0,null}.

Follow along with the example file

List.RemoveItems Function Examples.xlsx

Download

Example 5: Remove Filler Words From Text

List.RemoveItems also works on words once you split text into a list. Below is a table named Articles with the titles of travel blog posts, and I want a short keyword version of each title without words like “the” and “to”.

Articles table with four travel blog titles

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Articles"]}[Content],
Fillers = {"a","and","for","in","of","the","to"},
Keywords = Table.AddColumn(Source,"Keywords",each Text.Combine(List.RemoveItems(Text.Split([Title]," "),Fillers)," "))
in
Keywords

Result: A table with a new Keywords column: The Best Time Visit Iceland, How Pack Long Flight, A Weekend Scottish Highlands, and Packing List Ski Trip

The Keywords column with the filler words removed from each title

Here, the Fillers step holds the words to remove. For each row, the Text.Split function breaks the title into a list of words, List.RemoveItems takes out the filler words, and the Text.Combine function joins the rest back with spaces.

But look at the first and third rows. “The” and “A” are still there, because List.RemoveItems is case-sensitive, so “The” doesn’t match “the” in the Fillers list.

List.RemoveItems doesn’t have an option to ignore case. For that, use the List.RemoveMatchingItems function, which works the same way but takes a third argument that controls how values are compared.

To try it, replace the Keywords line with this one:

Keywords = Table.AddColumn(Source,"Keywords",each Text.Combine(List.RemoveMatchingItems(Text.Split([Title]," "),Fillers,Comparer.OrdinalIgnoreCase)," "))

Comparer.OrdinalIgnoreCase tells it to ignore upper and lower case. Now the first row becomes Best Time Visit Iceland and the third becomes Weekend Scottish Highlands.

Example 6: Remove Holidays From a List of Dates

Here’s a practical one for scheduling. Below is a table named Holidays with the office holidays at the end of December 2026, and I want the working days from December 21, 2026 to January 1, 2027.

Holidays table with four office holidays

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Holidays"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"Date",type date}}),
AllDays = List.Dates(#date(2026,12,21),12,#duration(1,0,0,0)),
Weekdays = List.Select(AllDays,each Date.DayOfWeek(_,Day.Monday)<5),
WorkDays = List.RemoveItems(Weekdays,Typed[Date])
in
WorkDays

Result: A list with 12/21/2026, 12/22/2026, 12/23/2026, 12/28/2026, 12/29/2026, and 12/30/2026

The six working days left after removing weekends and holidays

Here, the List.Dates function builds the 12 dates from December 21 to January 1. The Weekdays step uses the List.Select function to keep only Monday to Friday, and List.RemoveItems takes out the four holidays.

The Typed step matters. Dates from an Excel table come into Power Query as date and time values, and a date-and-time value never matches a plain date, so without the Typed step nothing would be removed.

The dates show up as 12/21/2026 and so on because my computer uses US date settings. On a computer with UK settings, you’d see 21/12/2026, but they’re the same dates.

Example 7: Change the Type of Every Column Except One

In this last example, the list is a table’s column names. Below is a table named MonthlySales with sales for each branch.

Columns from an Excel table come into Power Query with no data type, which is the ABC123 icon in each column header. I want every month column set to a number type, without typing each month’s name into the code.

MonthlySales table with sales for each branch from Jan to Apr

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="MonthlySales"]}[Content],
NumberCols = List.RemoveItems(Table.ColumnNames(Source),{"Branch"}),
Typed = Table.TransformColumnTypes(Source,List.Transform(NumberCols,each {_,type number}))
in
Typed

Result: The same table, with the Jan, Feb, Mar, and Apr columns set to the Decimal Number type (the 1.2 icon in the header)

The month columns now have the number type

Here, the Table.ColumnNames function returns all five column names, and List.RemoveItems takes out Branch. That leaves the four month names, which you can see if you click the NumberCols step.

The List.Transform function then turns each month name into a pair like {"Jan",type number}, which is the form Table.TransformColumnTypes needs.

You never type the month names in the code. When May gets added to the table, click Refresh and it gets the number type too.

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.