---
title: Table.IsEmpty – ตรวจสอบว่าตารางว่างหรือไม่
url: https://www.thepexcel.com/functions/power-query/table-functions/table-isempty/
type: function-explainer
program: Power Query
syntax: Table.IsEmpty(table as table) as logical
date: 2025-12-15
updated: 2025-12-24
scores:
  popularity: 5
  difficulty: 4
  usefulness: 6
---

# Table.IsEmpty – ตรวจสอบว่าตารางว่างหรือไม่

> Table.IsEmpty ใช้สำหรับตรวจสอบว่าตารางไม่มีข้อมูล (ไม่มีแถว) ใช่หรือไม่ คืนค่า true หากตารางว่าง fal

## คำอธิบาย

Table.IsEmpty ใช้สำหรับตรวจสอบว่าตารางไม่มีข้อมูล (ไม่มีแถว) ใช่หรือไม่ คืนค่า true หากตารางว่าง false หากมีข้อมูลอย่างน้อย 1 แถว

## Syntax

```excel
Table.IsEmpty(table as table) as logical
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| table | Yes | table |  | ตารางที่ต้องการตรวจสอบว่างหรือไม่ |

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

### ตรวจสอบก่อนเริ่มประมวลผลเพื่อป้องกัน Error

ตรวจสอบก่อนเริ่มประมวลผลเพื่อป้องกัน Error

### ตรวจสอบผลลัพธ์การกรองข้อมูลว่าเหลือข้อมูลหรือไม่

ตรวจสอบผลลัพธ์การกรองข้อมูลว่าเหลือข้อมูลหรือไม่

### ใช้ในการสร้างเงื่อนไขจัดการกรณีไม่มีข้อมูล (Empty State)

ใช้ในการสร้างเงื่อนไขจัดการกรณีไม่มีข้อมูล (Empty State)

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ตรวจสอบตารางที่มีข้อมูล

```excel
let
    Source = Table.FromRecords({[CustomerID=1, Name="Alice"]}),
    IsEmpty = Table.IsEmpty(Source)
in
    IsEmpty
```

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

ตารางมีข้อมูล 1 แถว ดังนั้น Table.IsEmpty จึงคืนค่า false (ตารางไม่ว่าง)

### 2. ตัวอย่างที่ 2: ตรวจสอบตารางเปล่า

```excel
let
    Source = Table.FromRecords({}),
    IsEmpty = Table.IsEmpty(Source)
in
    IsEmpty
```

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

ตารางไม่มีแถวข้อมูลเลย (0 แถว) ดังนั้น Table.IsEmpty จึงคืนค่า true (ตารางว่าง)

### 3. ตัวอย่างที่ 3: ตรวจสอบผลลัพธ์หลังการกรองข้อมูล

```excel
let
    Sales = Table.FromRecords({[Region="North", Amount=1000], [Region="South", Amount=2000]}),
    FilteredEast = Table.SelectRows(Sales, each [Region] = "East"),
    CheckEmpty = Table.IsEmpty(FilteredEast)
in
    CheckEmpty
```

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

กรองข้อมูลแล้วไม่เหลือแถวที่ตรงเงื่อนไข (ไม่มี Region="East") ตารางผลลัพธ์จึงเป็นตารางว่าง

### 4. ตัวอย่างที่ 4: ใช้กับ if condition สำหรับ error handling

```excel
let
    Data = Table.FromRecords({}),
    Result = if Table.IsEmpty(Data) then "No data found" else Table.RowCount(Data)
in
    Result
```

**ผลลัพธ์:** `"No data found"`

เมื่อตารางว่าง ใช้ if condition เพื่อแสดงข้อความแทนที่จะพยายามประมวลผลข้อมูลที่ไม่มี

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

- ใช้ Table.IsEmpty กับ if-then-else เพื่อสร้าง data validation logic

- สำหรับกรณี edge case เช่น "ไม่มีข้อมูลที่ตรงเงื่อนไขหลังจากกรอง" ให้ใช้ Table.IsEmpty ตรวจสอบก่อน

- ถ้าต้องการตรวจสอบ null table ให้ใช้ if x = null หรือ try-catch ก่อน

- ประสิทธิภาพดี ใช้ได้แม้กับ large dataset เพราะไม่ต้องดึงข้อมูลทั้งหมด

- ใช้ร่วมกับ Table.SelectRows หรือ Table.FirstN เพื่อตรวจสอบผลลัพธ์

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

**Q: ต่างระหว่าง Table.IsEmpty กับ Table.RowCount อย่างไร?**

Table.IsEmpty คืนค่า true/false ส่วน Table.RowCount คืนค่าตัวเลขจำนวนแถว ใช้ Table.IsEmpty เมื่อต้องการตัดสินใจ if/else ใช้ Table.RowCount เมื่อต้องการรู้จำนวนที่แน่นอน

**Q: Table.IsEmpty จะหลวมหรือเข้มงวด?**

เข้มงวด - ตรวจเฉพาะจำนวนแถว ไม่สนใจว่าตารางมีคอลัมน์หรือเพียงว่างเปล่า แม้ตารางจะถูกสร้างจาก record ที่มี schema แต่ถ้าไม่มีแถว ก็ถือว่าว่าง

**Q: ใช้กับ null table ได้ไหม?**

ไม่ได้ จะเกิด error หากอินพุตเป็น null ต้องป้องกัน null ก่อนใช้ Table.IsEmpty โดยใช้ try-catch หรือ if x is table

**Q: ประสิทธิภาพเป็นอย่างไร?**

เร็วมาก ไม่ต้องดึงข้อมูลทั้งหมด เพียงแค่ตรวจสอบว่ามีแถวหนึ่งแถวขึ้นไป ใช้ได้ปลอดภัยแม้กับ large dataset

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

- [Table.RowCount – นับจำนวนแถวในตาราง](https://www.thepexcel.com/functions/power-query/table-functions/table-rowcount/)
- [List.IsEmpty – ตรวจสอบว่ารายการว่างเปล่า](https://www.thepexcel.com/functions/power-query/list-functions/list-isempty/)

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

- [Microsoft Learn: Table.IsEmpty](https://learn.microsoft.com/en-us/powerquery-m/table-isempty) _(official)_
- [PowerQuery.how - M Language Reference](https://powerquery.how/) _(article)_

---

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