---
title: List.IsDistinct – ตรวจสอบว่าสมาชิกใน List ไม่ซ้ำกันเลยหรือไม่
url: https://www.thepexcel.com/functions/power-query/list-functions/list-isdistinct/
type: function-explainer
program: Power Query
syntax: "List.IsDistinct(list as list, optional equationCriteria as any) as logical"
date: 2025-12-03
updated: 2025-12-26
scores:
  popularity: 5
  difficulty: 4
  usefulness: 5
---

# List.IsDistinct – ตรวจสอบว่าสมาชิกใน List ไม่ซ้ำกันเลยหรือไม่

> List.IsDistinct ตรวจสอบว่า List มีค่าซ้ำหรือไม่ คืนค่า true ถ้าไม่มีตัวซ้ำเลย

## คำอธิบาย

List.IsDistinct ตรวจสอบว่า List มีค่าซ้ำหรือไม่ คืนค่า true ถ้าไม่มีตัวซ้ำเลย

## Syntax

```excel
List.IsDistinct(list as list, optional equationCriteria as any) as logical
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| list | Yes | list |  | List ที่ต้องการตรวจสอบ |
| equationCriteria | No | any | null | ตัวเลือกเสริมสำหรับกำหนดเกณฑ์การเปรียบเทียบ (เช่น Comparer.OrdinalIgnoreCase) |

## เคสการใช้งาน

### ตรวจสอบคุณภาพข้อมูล (Data Quality)

ใช้ตรวจสอบคอลัมน์ที่ควรจะเป็น Primary Key (ห้ามซ้ำ) ว่ามีค่าซ้ำหลุดมาหรือไม่

### Validation ก่อนประมวลผล

ตรวจสอบว่ารายการ Input ไม่มีการป้อนข้อมูลซ้ำก่อนที่จะนำไปคำนวณต่อ

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: List ที่ไม่มีตัวซ้ำ

```excel
List.IsDistinct({1, 2, 3})
```

**ผลลัพธ์:** `true`

สมาชิก 1, 2, 3 ไม่ซ้ำกันเลย จึงคืนค่า true

### 2. ตัวอย่างที่ 2: List ที่มีตัวซ้ำ

```excel
List.IsDistinct({1, 2, 3, 3})
```

**ผลลัพธ์:** `false`

มีเลข 3 ซ้ำกัน 2 ตัว จึงคืนค่า false

### 3. ตัวอย่างที่ 3: ตรวจสอบแบบไม่สนใจตัวพิมพ์เล็ก-ใหญ่

```excel
List.IsDistinct({"A", "a", "b"}, Comparer.OrdinalIgnoreCase)
```

**ผลลัพธ์:** `false`

ปกติ "A" กับ "a" ถือว่าต่างกัน (Distinct) แต่เมื่อใช้ Comparer.OrdinalIgnoreCase จะถือว่าซ้ำกัน จึงคืนค่า false

### 4. ตัวอย่างที่ 4: ตรวจสอบ List ว่าง

```excel
List.IsDistinct({})
```

**ผลลัพธ์:** `true`

List ว่างไม่มีตัวซ้ำ ดังนั้นจึงคืนค่า true (ไม่มีค่าใดที่ซ้ำกัน)

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

- ผมแนะนำใช้ List.IsDistinct ตรวจสอบคุณภาพข้อมูลก่อนโหลดเข้าโมเดล หากไม่ Distinct ต้องตรวจสอบแหล่งข้อมูลต่อ

- ส่วนตัวผม ผมรักษาความระมัดระวังกับการใช้ Comparer.OrdinalIgnoreCase เพราะจะมีผลต่อการเปรียบเทียบหลายๆ ครั้ง

- ใช้ List.IsDistinct({}) ตรวจสอบ List ว่างจะคืนค่า true (ไม่มีตัวซ้ำในกลุ่มว่าง)

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

**Q: List.IsDistinct ต่างจาก List.Distinct อย่างไร?**

ผมอธิบายง่ายๆ List.IsDistinct คืนค่า True/False (เพื่อตรวจสอบ) ส่วน List.Distinct คืนค่าเป็น List ใหม่ที่ตัดตัวซ้ำออกแล้ว (เพื่อจัดการข้อมูล) ผมใช้ IsDistinct เมื่อต้องการแค่ตรวจสอบ

**Q: ใช้กับค่า Null หรือค่าว่างได้ไหม?**

ได้ ผม List.IsDistinct({1, null, null}) ก็คืนค่า false เพราะ null ถือว่าเป็นค่าซ้ำกัน Null ที่ซ้ำกันถือเป็นการไม่ Distinct

**Q: ใช้กับ List ของ Record ได้ไหม?**

ได้ แต่ผมแนะนำให้ใช้ equationCriteria เพื่อกำหนดว่าจะเปรียบเทียบ Field ไหนของ Record ถ้าไม่ระบุมันจะเปรียบเทียบ Record ทั้งหมด

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

- [List.Distinct – ลบค่าซ้ำออกจาก List](https://www.thepexcel.com/functions/power-query/list-functions/list-distinct/)
- [List.Count – นับจำนวนรายการในลิสต์](https://www.thepexcel.com/functions/power-query/list-functions/list-count/)
- [Table.IsDistinct – จัดการตาราง](https://www.thepexcel.com/?post_type=function-explainer&p=37985)

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

- [Microsoft Learn: List.IsDistinct](https://learn.microsoft.com/en-us/powerquery-m/list-isdistinct) _(official)_

---

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