List.Difference 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.Difference function in Power Query gives you the values in one list that aren’t in another list. You give it two lists, and it returns what’s left in the first one after taking out everything found in the second.

This is how you find the documents someone still needs to send, the employees who haven’t finished a training, or the invoice numbers missing from a sequence.

Follow along with the example file

List.Difference Function Examples.xlsx

Download

List.Difference Function Syntax

List.Difference(list1 as list, list2 as list, optional equationCriteria as any) as list
  • list1 – the list you start with. The result only ever contains values from this list.
  • list2 – the list of values to take out of list1.
  • equationCriteria (optional) – tells List.Difference how to decide that two values match. For example, Comparer.OrdinalIgnoreCase makes it ignore upper and lower case (Example 4).

What it returns: A list of what’s left of list1 after the values in list2 are taken out, in list1’s order. Each value in list2 takes out only one matching copy from list1, so repeated values need a closer look (Example 6).

The List.Difference 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.Difference Function

Use this function when you need to:

  • Find the items in one list that are missing from another list
  • Find the mismatches between two lists, in both directions
  • Find the customers, employees, or IDs in one table that aren’t in another table
  • Compare values that differ only in upper and lower case, or have extra spaces
  • Find the gaps in a sequence of invoice or order numbers
  • Find the dates that have no entry in your data
  • Check whether a table has all the columns it should have

Example 1: Find the Items Missing From a List

Let’s start with a simple one. Suppose a loan application needs five documents (ID Proof, Address Proof, Pay Slips, Bank Statement, and Tax Return), the applicant has sent Pay Slips, ID Proof, and Tax Return, and you want to know what’s still missing.

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.Difference({"ID Proof","Address Proof","Pay Slips","Bank Statement","Tax Return"},{"Pay Slips","ID Proof","Tax Return"})

Result: A list with Address Proof and Bank Statement

List.Difference returns Address Proof and Bank Statement, the documents not yet submitted

Here, the first list holds the required documents and the second list holds the ones that came in. List.Difference goes through the first list and drops every document it finds in the second, so Address Proof and Bank Statement are left.

The order of the two lists matters. If you swap them, you’re asking which submitted documents aren’t required, and the answer here is an empty list.

The result also follows the order of the first list, so the missing documents come back in the same order as the required list.

If you want the opposite, the documents that are in both lists, use the List.Intersect function instead.

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: Find the Differences in Both Directions

Since List.Difference only looks one way, you sometimes need to run it twice. Suppose a small gift shop has one product list in its warehouse system and another on its online store, and you want every product that’s in one list but not the other.

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

let
Warehouse = {"Candle","Mug","Tote Bag","Notebook","Coaster"},
Online = {"Mug","Notebook","Poster","Coaster","Keychain"},
NotOnline = List.Difference(Warehouse,Online),
NotInWarehouse = List.Difference(Online,Warehouse),
Mismatches = List.Combine({NotOnline,NotInWarehouse})
in
Mismatches

Result: A list with Candle, Tote Bag, Poster, and Keychain

List.Combine joins both one-way differences: Candle, Tote Bag, Poster and Keychain

Here, the NotOnline step finds the warehouse products that aren’t on the online store (Candle and Tote Bag). The NotInWarehouse step swaps the lists and finds the online products the warehouse doesn’t have (Poster and Keychain).

The last step uses the List.Combine function to join the two results into one list. The warehouse-only products come first because NotOnline is first inside the curly brackets.

If you want to see the two groups separately, click the NotOnline or NotInWarehouse step in the Applied Steps pane.

Example 3: Compare Two Tables

This one comes up a lot with real data. I have a table of all staff and another table of the people who’ve completed a safety training, and I want the people who still need to do it.

Below is the staff table, on the Example 3 Staff sheet.

AllStaff table with each employee and department

And here is the training table, on the Example 3 Training sheet. It has the name of each person who finished the training and the date they finished it.

TrainingDone table with the employees who finished the training

The two tables are Excel Tables named AllStaff and TrainingDone. The code below reads them by those names, so for your own data, change the names to match your tables.

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

let
Source = Excel.CurrentWorkbook(){[Name="AllStaff"]}[Content],
Trained = Excel.CurrentWorkbook(){[Name="TrainingDone"]}[Content],
NotTrained = List.Difference(Source[Employee],Trained[Employee])
in
NotTrained

Result: A list with Ryan Fisher, Hailey Thompson, and Jacqueline Cook

Ryan Fisher, Hailey Thompson and Jacqueline Cook still need the training

Here, the Source step reads the staff table and the Trained step reads the training table. Source[Employee] and Trained[Employee] each give the Employee column as a list, and List.Difference keeps the staff names that aren’t in the training list.

The result is a list of names. If you need the full rows for those people (with their departments), merge the two tables with a left anti join instead (Home > Merge Queries, then pick Left Anti as the Join Kind).

Example 4: Ignore Upper and Lower Case

By default, List.Difference treats “TX-100” and “tx-100” as two different values. I have my catalog SKUs in one table and my website SKUs in another, some typed in lowercase, and I want the catalog products that aren’t on the website.

Below is the catalog table, named CatalogSKUs, on the Example 4 Catalog sheet.

CatalogSKUs table with six catalog SKUs

And here is the website table, named WebsiteSKUs, on the Example 4 Website sheet.

WebsiteSKUs table where some SKUs are typed in lowercase

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

let
Source = Excel.CurrentWorkbook(){[Name="CatalogSKUs"]}[Content],
Website = Excel.CurrentWorkbook(){[Name="WebsiteSKUs"]}[Content],
NotListed = List.Difference(Source[Catalog SKU],Website[Website SKU],Comparer.OrdinalIgnoreCase)
in
NotListed

Result: A list with TR-415 and TL-630

With Comparer.OrdinalIgnoreCase only TR-415 and TL-630 are missing from the website

Here, Comparer.OrdinalIgnoreCase is the third argument, and it tells List.Difference to ignore upper and lower case when it compares the SKUs. So TX-100 matches tx-100, and TL-520 matches tl-520.

Without it, you’d get TX-100, TR-415, TL-520, and TL-630. TX-100 and TL-520 are on the website, but the lowercase spelling makes them look missing.

Example 5: Ignore Case and Extra Spaces

Comparer.OrdinalIgnoreCase only takes care of case, so an email with a stray space still won’t match its clean version.

I have one table with the emails of the people invited to an event and another with the emails of the people who replied, and I want the people who haven’t replied.

Below is the Invited table, on the Example 5 Invited sheet.

Invited table with six guest emails

And here is the Replied table, on the Example 5 Replied sheet. Some replies use different capital letters, and two have a stray space: Seth’s has one at the end and Ryan’s has one at the start.

Replied table with mixed-case emails and stray spaces

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

let
Source = Excel.CurrentWorkbook(){[Name="Invited"]}[Content],
Replied = Excel.CurrentWorkbook(){[Name="Replied"]}[Content],
NoReply = List.Difference(Source[Email],Replied[Email],each Text.Lower(Text.Trim(_)))
in
NoReply

Result: A list with ronald.wallace@example.com and kelsey.sanders@example.com

The trim-and-lowercase key function leaves only the two guests who haven't replied

Here, the third argument is a function instead of a comparer (a built-in matching rule like Comparer.OrdinalIgnoreCase in Example 4).

each Text.Lower(Text.Trim(_)) removes the spaces around each email and turns it into lowercase, and List.Difference compares these cleaned-up versions instead of the original values.

The result still shows the emails exactly as they are in the Invited table. The function is only used for the comparison and doesn’t change what you get back.

With Comparer.OrdinalIgnoreCase instead, Monica’s reply would match, but Seth’s and Ryan’s wouldn’t, because of the extra spaces. You’d get four emails instead of two.

Follow along with the example file

List.Difference Function Examples.xlsx

Download

Example 6: Understand How Repeated Values Are Handled

This is the part of List.Difference that surprises people. Suppose you sold six tickets to an event (two VIP, three General, and one Student), three of them have been scanned at the gate so far, and you want the tickets that haven’t been scanned yet.

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

let
Sold = {"VIP","General","General","Student","General","VIP"},
Scanned = {"General","VIP","General"},
NotArrived = List.Difference(Sold,Scanned)
in
NotArrived

Result: A list with Student, General, and VIP

Each scanned ticket removes one match, leaving Student, General and VIP

Here, List.Difference doesn’t remove every General and every VIP. Each value in the second list takes out only one matching value from the first list.

General was scanned twice, so two of the three General tickets are taken out and one is left. VIP was scanned once, so one of the two VIP tickets is left.

The earliest matching copies are the ones taken out, so the tickets left are the last General and the last VIP. That’s why Student comes first in the result.

That’s three tickets still to come, one of each type.

For the ticket types that haven’t had a single scan, use the List.RemoveItems function. It takes the same two lists, but it removes every copy of a value that shows up anywhere in the second list.

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

NoScans = List.RemoveItems(Sold,Scanned)

Also change the last line from NotArrived to NoScans. Now you get only Student, because every General and every VIP ticket is removed.

Example 7: Find the Missing Numbers in a Sequence

Here’s a practical use you might not think of. Below is a table named Invoices with invoice numbers that should run from 2041 to 2052 without a break, and I want to find the numbers that are missing.

Invoices table with gaps in the invoice numbers

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

let
Source = Excel.CurrentWorkbook(){[Name="Invoices"]}[Content],
FullRange = {List.Min(Source[Invoice No])..List.Max(Source[Invoice No])},
Missing = List.Difference(FullRange,Source[Invoice No])
in
Missing

Result: A list with 2044, 2049, and 2050

List.Difference finds the missing invoice numbers 2044, 2049 and 2050

Here, the FullRange step builds the complete sequence. The List.Min function gets the smallest invoice number (2041), the List.Max function gets the largest (2052), and the two dots between them create every whole number from 2041 to 2052.

List.Difference then takes out the numbers that are in the table, and what’s left are the gaps.

Since FullRange is built from the smallest and largest numbers in the table, it updates on its own. Add invoices 2053 and 2055 to the table, click Refresh, and you’d see 2054 added to the missing list.

This works because the Invoice No column holds real numbers. If your invoice numbers are stored as text, the FullRange step returns an error, because the two dots can’t build a range between text values like “2041” and “2052”.

In that case, add a step after Source that changes the column to whole numbers, Typed = Table.TransformColumnTypes(Source,{{"Invoice No",Int64.Type}}), and use Typed[Invoice No] instead of Source[Invoice No] in the FullRange and Missing steps.

Example 8: Find the Missing Dates

The same idea works with dates.

Below is a table named DailySales with a daily sales log for the first two weeks of November 2026. Some days have no row, and I want to find them.

DailySales table, with the dates arriving as date and time values

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

let
Source = Excel.CurrentWorkbook(){[Name="DailySales"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"Date",type date}}),
AllDates = List.Dates(#date(2026,11,1),14,#duration(1,0,0,0)),
Missing = List.Difference(AllDates,Typed[Date])
in
Missing

Result: A list with 11/5/2026 and 11/10/2026

11/5/2026 and 11/10/2026 have no sales entry

Here, the List.Dates function builds a list of 14 dates, one day apart, starting on 11/1/2026. List.Difference takes out the dates that are in the table and leaves the two days with no entry.

The start date and the 14 are the period you want to check, so change them to match your data. With a fixed period, the query also catches a missing first or last day, which a list built from the table’s own dates would miss.

The Typed step uses the Table.TransformColumnTypes function to change the Date column to plain dates. That step matters, because dates from an Excel table come into Power Query as date and time values.

A date-and-time value never matches a plain date, even when it’s the same day. Without the Typed step, you’d get all 14 dates back.

The dates show up as 11/5/2026 and 11/10/2026 because my computer uses US date settings. On a computer with UK settings, you’d see 05/11/2026 and 10/11/2026, but they’re the same dates.

Example 9: Find the Columns Missing From a Table

In this last example, the lists are column names. Suppose every sales export you get should have five columns (Order ID, Order Date, Store, Amount, and Region).

Below is a table named SalesExport from one of those exports, and I want to check which of the five columns it doesn’t have.

SalesExport table with three columns

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

let
Source = Excel.CurrentWorkbook(){[Name="SalesExport"]}[Content],
Required = {"Order ID","Order Date","Store","Amount","Region"},
MissingColumns = List.Difference(Required,Table.ColumnNames(Source))
in
MissingColumns

Result: A list with Order Date and Region

Order Date and Region are the required columns the export doesn't have

Here, the Required step holds the five column names the export should have. The Table.ColumnNames function returns the names of the columns the table actually has, and List.Difference keeps the required names that aren’t among them.

This is a good check to run before the rest of your query. If a later step uses the Region column and an export doesn’t have it, that step fails with an error, and this list tells you straight away which columns are missing.

Other Excel Articles You May Also Like:

  • List.Distinct – Use List.Distinct in Power Query M to remove duplicates from a list.
  • List.IsDistinct – Use List.IsDistinct in Power Query M to check if every value in a list is unique.
  • List.Contains – Use List.Contains in Power Query M to check if a value exists in a list.
  • List.IsEmpty – Use List.IsEmpty in Power Query M to check whether a list has values or is empty.
  • Table.Distinct – Use Table.Distinct in Power Query M to remove duplicate rows.
  • List.MatchesAny – Use List.MatchesAny in Power Query M to check if any item meets a condition.
  • List.Combine – Use List.Combine in Power Query M to join lists into one.
  • Table.Join – Use Table.Join in Power Query M to join two tables.

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.