---
title: Table.Distinct – ลบแถวที่ซ้ำกันออกจากตาราง
url: https://www.thepexcel.com/functions/power-query/table-functions/table-distinct/
type: function-explainer
program: Power Query
syntax: "Table.Distinct(table as table, optional equationCriteria as any) as table"
date: 2025-12-03
updated: 2025-12-23
scores:
  popularity: 8
  difficulty: 2
  usefulness: 8
---

# Table.Distinct – ลบแถวที่ซ้ำกันออกจากตาราง

> Table.Distinct ลบแถวที่ซ้ำกันออกจากตารางตามคอลัมน์ที่กำหนด หรือทั้งตารางถ้าไม่ระบุคอลัมน์

## คำอธิบาย

Table.Distinct ลบแถวที่ซ้ำกันออกจากตารางตามคอลัมน์ที่กำหนด หรือทั้งตารางถ้าไม่ระบุคอลัมน์

## Syntax

```excel
Table.Distinct(table as table, optional equationCriteria as any) as table
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| table | Yes | Table |  | ตารางที่ต้องการลบแถวซ้ำกัน |
| equationCriteria | No | Text or List | ทั้งแถว | คอลัมน์ที่ต้องการใช้ในการเช็คการซ้ำกัน (ถ้าไม่ระบุจะเช็คทั้งแถว) |

## ตัวอย่าง

### 1. ตัวอย่างพื้นฐาน - ลบแถวซ้ำทั้งหมด

```excel
let
    Sales = Table.FromRecords({
        [ProductID = 1, Product = "Laptop", Price = 999],
        [ProductID = 2, Product = "Mouse", Price = 25],
        [ProductID = 1, Product = "Laptop", Price = 999]
    }),
    Unique = Table.Distinct(Sales)
in
    Unique
```

**ผลลัพธ์:** `ตารางมี 2 แถว (แถวที่ 3 ซ้ำกับแถวที่ 1 ถูกลบออก)`

ตั้งแต่ไม่ระบุ equationCriteria ก็จะเช็คแถวทั้งหมด ถ้าข้อมูลทั้ง 3 คอลัมน์เหมือนกันแบบเดียวกันจะถือว่าซ้ำกัน

### 2. ลบแถวซ้ำตามคอลัมน์เดียว

```excel
let
    Customers = Table.FromRecords({
        [CustomerID = "C001", Name = "John", City = "Bangkok"],
        [CustomerID = "C002", Name = "Jane", City = "Bangkok"],
        [CustomerID = "C001", Name = "John", City = "Chiang Mai"]
    }),
    UniqueByID = Table.Distinct(Customers, "CustomerID")
in
    UniqueByID
```

**ผลลัพธ์:** `ตารางมี 2 แถว (เก็บแถวแรกของแต่ละ CustomerID)`

ระบุให้ดูเฉพาะคอลัมน์ CustomerID ถ้า CustomerID ซ้ำจะลบแถวที่ 3 ออก แม้ว่า City ต่างกันก็ตาม

### 3. ลบแถวซ้ำตามหลายคอลัมน์

```excel
let
    Orders = Table.FromRecords({
        [OrderID = 1, CustomerID = "C001", Amount = 500],
        [OrderID = 2, CustomerID = "C002", Amount = 300],
        [OrderID = 3, CustomerID = "C001", Amount = 500]
    }),
    UniqueByIDAmount = Table.Distinct(Orders, {"CustomerID", "Amount"})
in
    UniqueByIDAmount
```

**ผลลัพธ์:** `ตารางมี 2 แถว (ลบแถวที่ซ้ำกันในทั้ง CustomerID และ Amount)`

ใช้ list {"CustomerID", "Amount"} เพื่อเช็คความซ้ำกันตามสองคอลัมน์พร้อมกัน

### 4. ประยุกต์ใช้ - ข้อมูลอีเมลจากหลายแหล่ง

```excel
let
    ImportedEmails = Table.FromRecords({
        [Email = "john@example.com", Source = "LinkedIn"],
        [Email = "jane@example.com", Source = "Facebook"],
        [Email = "john@example.com", Source = "Gmail"],
        [Email = "bob@example.com", Source = "LinkedIn"]
    }),
    UniqueEmails = Table.Distinct(ImportedEmails, "Email"),
    Result = Table.SelectColumns(UniqueEmails, {"Email"})
in
    Result
```

**ผลลัพธ์:** `ตารางมี 3 แถว (john@example.com, jane@example.com, bob@example.com)`

ดึงข้อมูลอีเมลจากหลายแหล่ง Table.Distinct ลบที่ซ้ำกัน เก็บเฉพาะแถวแรกของแต่ละอีเมล

## หมายเหตุเพิ่มเติม

- ถ้าต้องการเก็บแถวแรกที่ซ้ำกันให้เรียง (Table.Sort) ก่อน Table.Distinct เพื่อให้ได้ผลลัพธ์ที่คาดหวัง

- ใช้ Table.Buffer() ก่อน Table.Distinct ถ้าข้อมูลมีคุณสมบัติพิเศษที่ต้องการความแน่นอนในการทำงาน

- สามารถใช้ร่วมกับ Table.SelectRows, Table.SelectColumns, Table.Group ได้

- equationCriteria สามารถเป็น text ซ้ำคอลัมน์เดียว หรือ list ถ้าหลายคอลัมน์

## คำถามที่พบบ่อย

**Q: Table.Distinct กับ Table.SelectRows ต่างกันอย่างไร?**

Table.Distinct ลบแถวที่ซ้ำกัน ส่วน Table.SelectRows กรองแถวตามเงื่อนไข ทั้งสองใช้คนละวัตถุประสงค์

**Q: ถ้าข้อมูลมีเยอะ Table.Distinct จะช้าไหม?**

ตัว Power Query จะทำให้เร็วที่สุดตามที่เป็นไปได้ ถ้ากังวลใจให้ใช้ Table.Buffer() ก่อน Table.Distinct เพื่อให้มั่นใจในการทำงาน

**Q: ข้อมูลซ้ำไป แถวไหนถูกเก็บไว้?**

ไม่มีการรับประกัน Power Query จะทำการเลือกแบบที่มันเห็นสมควร ถ้าต้องการความแน่นอน (เช่น ต้องเก็บแถวแรก) ให้เรียง Table.Sort() ก่อน

**Q: สามารถลบแถวซ้ำตามคอลัมน์ที่คำนวณได้ไหม?**

ได้ สร้างคอลัมน์ใหม่ที่มีค่าที่ต้องการก่อน แล้วใช้ Table.Distinct ตามคอลัมน์นั้น

## ฟังก์ชันที่เกี่ยวข้อง

- table-select-rows
- [Table.Buffer – โหลดตารางเข้า Memory เพื่อความเร็ว](https://www.thepexcel.com/functions/power-query/table-functions/table-buffer/)
- [Table.Sort – เรียงลำดับข้อมูลในตาราง](https://www.thepexcel.com/functions/power-query/table-functions/table-sort/)
- [Table.Group – จัดกลุ่มและสรุปผลข้อมูล (Group By)](https://www.thepexcel.com/functions/power-query/table-functions/table-group/)

## แหล่งข้อมูลเพิ่มเติม

- [Microsoft Learn - Table.Distinct](https://learn.microsoft.com/en-us/powerquery-m/table-distinct) _(official)_
- [Power Query M Language Reference](https://learn.microsoft.com/en-us/powerquery-m/) _(official)_
- [Table Functions in Power Query](https://learn.microsoft.com/en-us/powerquery-m/table-functions) _(official)_

---

_Source: [https://www.thepexcel.com/functions/power-query/table-functions/table-distinct/](https://www.thepexcel.com/functions/power-query/table-functions/table-distinct/)_
