The Table.Distinct function in Power Query removes duplicate rows from a table. You can check every column for duplicates, or only the columns you pick, like an ID or an email address.
It’s also the function Power Query writes for you when you right-click a column header and choose Remove Duplicates.
In this article, I’ll show you how to use it with practical examples, from removing exact duplicate rows to keeping only the latest record for each ID.
Follow along with the example file
Table.Distinct Function Examples.xlsx
Table.Distinct Function Syntax
= Table.Distinct(table as table, optional equationCriteria as any) as table
- table – the table you want to remove duplicate rows from. This is usually the previous step, such as
Source. - equationCriteria (optional) – the columns that should be checked for duplicates. Give one column name as text, or several names as a list in curly brackets, such as
{"Vendor","Invoice No"}. You can also pair a column with a comparer, like{"Email",Comparer.OrdinalIgnoreCase}, to ignore upper and lower case. If you leave it out, all the columns are checked.
What it returns – a table with the duplicate rows removed. All the columns stay, and one row from each group of duplicates is kept.
The Table.Distinct 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.Distinct Function
Use this function when you need to:
- Remove rows that were entered or imported twice
- Keep one row per customer, order, or ID, even when the other columns differ
- Remove duplicates based on a combination of columns, like vendor and invoice number
- Treat “ABC@mail.com” and “abc@mail.com” as the same value
- Keep only the latest (or first) record for each ID
- Get the unique values from a column, like all the regions in a sales table
Example 1: Remove Exact Duplicate Rows
Let’s start with the simplest use, where you remove rows that are exact copies of another row.
Below is a list of webinar registrations where a few people signed up twice, and I want to remove the repeated rows.

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.Distinct(Source)
Result: a table with 6 rows, with the second Samantha Stewart and Craig Robinson rows removed

Here, I only gave the table, so Table.Distinct compares every column. A row is removed only when its Name, Email, and Session all match an earlier row.
That’s why Jocelyn Roberts still shows up twice. She registered for two different sessions, so her two rows aren’t duplicates.
Example 2: Remove Duplicates Based on One Column
Most of the time, duplicates aren’t exact copies. The same ID shows up again, but something else in the row is different.
Below is a customer list combined from two systems, where some Customer IDs appear twice, and I want to keep only one row for each Customer ID.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Distinct(Source,{"Customer ID"})
Result: a table with 5 rows, one for each Customer ID from C-101 to C-105

Here, the second argument tells Table.Distinct to check only the Customer ID column. C-101 appears twice, once with Denver and once with Boulder, and in this result the Denver row (the first one) is the one that stays.
Note that the result still has all three columns. Table.Distinct uses the column you name to find duplicates, but it never removes any columns.
You can get the same result without typing. Right-click the Customer ID header and choose Remove Duplicates, and Power Query adds a Removed Duplicates step with the same Table.Distinct formula, pointing to the previous step.
Power Query treats null IDs as equal. If you want to keep those rows separate, give them unique IDs before removing duplicates.
Important: Microsoft doesn’t guarantee which duplicate row Table.Distinct keeps. In every example in this article the first one stayed, but if it matters which row stays, sort and buffer the table first, as shown in Example 5.
Example 3: Remove Duplicates Based on Multiple Columns
Sometimes one column isn’t enough to tell whether a row is a duplicate.
Below is a list of vendor invoices where a couple of invoices were entered twice, and I want to keep one row for each Vendor and Invoice No combination.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Distinct(Source,{"Vendor","Invoice No"})
Result: a table with 5 rows, one for each Vendor and Invoice No combination

Here, a row counts as a duplicate only when both the Vendor and the Invoice No match an earlier row. Brightline Supplies’ second INV-1001 row is removed even though its amount is 455 instead of 450, because the Amount column isn’t checked.
Checking both columns matters here. Brightline Supplies and Northgate Paper both have an invoice called INV-1001, so Table.Distinct(Source,{"Invoice No"}) would wrongly remove Northgate Paper’s invoice.
To do this from the menu, hold the Control key (Command on a Mac), click the Vendor and Invoice No headers, then right-click one of them and choose Remove Duplicates.
Example 4: Remove Duplicates and Ignore Upper and Lower Case
By default, Table.Distinct is case-sensitive, so “awatson@mail.com” and “AWatson@mail.com” are two different values to it.
Below is a newsletter subscriber list where some people signed up twice with different capitalization in their email, and I want one row per email address.

If you use Table.Distinct(Source,{"Email"}) here, nothing is removed. All six rows stay because no two emails match exactly.
Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Distinct(Source,{"Email",Comparer.OrdinalIgnoreCase})
Result: a table with 4 rows, one for each email address

Here, {"Email",Comparer.OrdinalIgnoreCase} tells Table.Distinct to check the Email column and to ignore upper and lower case while doing it. So “AWatson@mail.com” now matches “awatson@mail.com”, and the later row is removed.
The kept rows show the email exactly as it appeared in that row. The function doesn’t change the text to lowercase, it only ignores case while comparing.
If you need to ignore case in more than one column, give a list of these pairs, such as {{"First Name",Comparer.OrdinalIgnoreCase},{"Last Name",Comparer.OrdinalIgnoreCase}}.
The same comparer works in other functions too. For example, the Table.Group function can use it to group “Electronics” and “electronics” together.
Follow along with the example file
Table.Distinct Function Examples.xlsx
Example 5: Keep Only the Latest Record for Each ID
This next one comes up all the time. You have several rows for the same ID, and you want to keep the newest one.
Below is an order status log with one row for every update, and I want to keep only the latest status for each Order ID.

This one needs a few steps, so it’s easier to paste the whole query. The Source line reads the Excel table named OrderUpdates, so change that name to your own table’s name.
Go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor, open the Advanced Editor (Home > Advanced Editor) and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="OrderUpdates"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Updated On",type date}}),
#"Sorted Rows" = Table.Buffer(Table.Sort(#"Changed Type",{{"Updated On",Order.Descending}})),
#"Removed Duplicates" = Table.Distinct(#"Sorted Rows",{"Order ID"})
in
#"Removed Duplicates"
Result: a table with 3 rows: ORD-501 Delivered on 3/7/2026, ORD-503 Cancelled on 3/6/2026, and ORD-502 Shipped on 3/5/2026

Here, the Changed Type step makes Updated On a date column. The Sorted Rows step then uses the Table.Sort function to sort the table by Updated On from newest to oldest, so the latest update for each order sits above the older ones.
Table.Distinct then keeps one row for each Order ID, which is the top one, the latest. The dates show as 3/7/2026 on a US setup, and in your own regional format otherwise.
The Table.Buffer function around the sort is what makes this reliable. It holds the sorted table in memory, so Table.Distinct sees the rows in that order and keeps the top one.
Important: Don’t skip Table.Buffer. Without it, Power Query may ignore the sort while removing duplicates, and you can end up with an older row instead of the latest one.
To keep the oldest record instead, sort with Order.Ascending.
Example 6: Get Unique Values from a Column
Table.Distinct is also handy for getting the unique values in a column, like the regions or product categories you can use as a lookup table.
Below is a sales table with the region, sales rep, and amount for each sale, and I want a list of the regions with each one appearing only once.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="Sales"]}[Content],
#"Removed Other Columns" = Table.SelectColumns(Source,{"Region"}),
#"Removed Duplicates" = Table.Distinct(#"Removed Other Columns")
in
#"Removed Duplicates"
Result: a one-column table with East, West, North, and South

Here, the Table.SelectColumns function first keeps only the Region column. Table.Distinct then removes the repeated regions, so East and West show up once each.
You need the Table.SelectColumns step here. If you use Table.Distinct(Source,{"Region"}) without it, you get one full row per region, with the sales rep and amount from whichever row Power Query keeps.
The result is still a table, which is what you want for a lookup table you load to a sheet or the Data Model.
If you need the values as a list instead (a single set of values with no column header), the List.Distinct function does the same job on a list.
Example 7: Remove Duplicates That Differ by Extra Spaces
Duplicates often hide behind extra spaces, especially in data typed by hand or exported from another system.
Below is a product list where a few SKUs have extra spaces before or after them, and I want to keep one row for each SKU.

The third SKU has two spaces before KB-110, and the fifth has two spaces after MS-205 (those don’t show in the cell). Table.Distinct compares the text exactly, so KB-110 with spaces in front is a different value from plain KB-110.
If you remove duplicates on the SKU column directly, all six rows stay.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="Products"]}[Content],
#"Trimmed Text" = Table.TransformColumns(Source,{{"SKU",Text.Trim,type text}}),
#"Removed Duplicates" = Table.Distinct(#"Trimmed Text",{"SKU"})
in
#"Removed Duplicates"
Result: a table with 4 rows, one each for KB-110, MS-205, HD-330, and WC-410

Here, the Trimmed Text step uses the Table.TransformColumns function to apply the Text.Trim function, which removes the spaces at the start and end of every SKU. Once those spaces are gone, the third SKU matches the first KB-110, and Table.Distinct removes it as a duplicate.
You can add the same step from the menu. Right-click the SKU header and choose Transform > Trim, then remove duplicates on the SKU column.
If your data also has mixed capitalization, you can combine this with the comparer from Example 4.
Example 8: Count How Many Duplicates Were Removed
Before removing duplicates from a large table, it helps to know how many rows you’ll lose.
Below is a log of employee badge scans where some scans were recorded more than once, and I want to know how many duplicate rows are in it.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="BadgeScans"]}[Content],
#"Duplicates Removed" = Table.RowCount(Source) - Table.RowCount(Table.Distinct(Source))
in
#"Duplicates Removed"
Result: 3

Here, the Table.RowCount function counts the rows in the original table (7) and in the table after Table.Distinct removes duplicates (4). The difference, 3, is the number of duplicate rows.
Joshua Warren’s Monday scan appears three times, so two of those rows are duplicates. Patrick Shaw’s Monday scan appears twice, which adds one more.
If the count is 0, the table has no duplicates. To simply check that, without counting, you can use the Table.IsDistinct function, which returns true or false.
Other Excel Articles You May Also Like:
- List.Sort
- Text.Replace
- Text.TrimEnd function
- List.IsDistinct – Use List.IsDistinct in Power Query M to check if every value in a list is unique.
- Table.SelectRows – Use Table.SelectRows in Power Query M to keep only the rows that meet a condition.
- Table.Join – Use Table.Join in Power Query M to join two tables.
- Table.NestedJoin – Use Table.NestedJoin in Power Query M to merge two tables.
- Table.AddRankColumn – Use Table.AddRankColumn in Power Query M to rank rows.