---
title: Table.SelectColumns – เลือกคอลัมน์ที่ต้องการจากตาราง
url: https://www.thepexcel.com/functions/power-query/table-functions/table-selectcolumns/
type: function-explainer
program: Power Query
syntax: "= Table.SelectColumns(table, columns, optional missingField)"
date: 2025-12-03
updated: 2025-12-20
scores:
  popularity: 9
  difficulty: 2
  usefulness: 9
---

# Table.SelectColumns – เลือกคอลัมน์ที่ต้องการจากตาราง

> Table.SelectColumns ใช้สำหรับเลือกคอลัมน์เฉพาะจากตารางและสร้างตารางใหม่ที่มีเฉพาะคอลัมน์เหล่านั้น

## คำอธิบาย

Table.SelectColumns ใช้สำหรับเลือกคอลัมน์เฉพาะจากตารางและสร้างตารางใหม่ที่มีเฉพาะคอลัมน์เหล่านั้น

## Syntax

```excel
= Table.SelectColumns(table, columns, optional missingField)
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| table | Yes | table |  | ตารางต้นฉบับที่ต้องการเลือกคอลัมน์ |
| columns | Yes | text or list |  | ชื่อคอลัมน์ที่ต้องการ (ข้อความเดี่ยว หรือ list of text) |
| missingField | No | MissingField code | Error (ค่าเริ่มต้นจะ error ถ้าหาคอลัมน์ไม่เจอ) | พฤติกรรมเมื่อคอลัมน์ไม่มี: MissingField.UseNull หรือ MissingField.Ignore |

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

### ลดขนาดข้อมูล

เลือกเฉพาะคอลัมน์ที่จำเป็นต้องใช้ในการวิเคราะห์ เพื่อลดการใช้หน่วยความจำ

### จัดลำดับคอลัมน์ใหม่

เมื่อระบุ List ของคอลัมน์ ผลลัพธ์จะเรียงลำดับตาม List นั้น (ใช้ Reorder ได้ในตัว)

## ตัวอย่าง

### 1. เลือกคอลัมน์เดี่ยว

```excel
let
    Source = Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"], [CustomerID = 2, Name = "Jim", Phone = "987-6543"]}),
    SelectedColumns = Table.SelectColumns(Source, "Name")
in
    SelectedColumns
```

**ผลลัพธ์:** `ตารางที่มีแค่คอลัมน์ Name ที่เหลือ 2 แถว`

ใช้ text string เดี่ยว "Name" เพื่อเลือกแค่คอลัมน์เดียว

### 2. เลือกหลายคอลัมน์พร้อมจัดเรียงลำดับ

```excel
let
    Source = Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"], [CustomerID = 2, Name = "Jim", Phone = "987-6543"]}),
    SelectedColumns = Table.SelectColumns(Source, {"Name", "CustomerID"})
in
    SelectedColumns
```

**ผลลัพธ์:** `ตารางสองคอลัมน์ชิด Name อยู่ซ้าย CustomerID อยู่ขวา`

ลำดับใน list {"Name", "CustomerID"} คือลำดับคอลัมน์ในผลลัพธ์ - จึงต่างจากตารางต้นฉบับ

### 3. ลองเลือกคอลัมน์ที่ไม่มีในตาราง (จะ error)

```excel
let
    Source = Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}),
    SelectedColumns = Table.SelectColumns(Source, {"CustomerID", "Email"})
in
    SelectedColumns
```

**ผลลัพธ์:** `Expression.Error: ไม่พบคอลัมน์ Email`

ค่าเริ่มต้น missingField ไม่ระบุ จึง error เมื่อขาด Email - เพื่อแก้ให้เพิ่ม MissingField.UseNull

### 4. ใช้ MissingField.UseNull เพื่อสร้างคอลัมน์ null

```excel
let
    Source = Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}),
    SelectedColumns = Table.SelectColumns(Source, {"CustomerID", "Email"}, MissingField.UseNull)
in
    SelectedColumns
```

**ผลลัพธ์:** `ตาราง 2 คอลัมน์: CustomerID = 1, Email = null`

MissingField.UseNull สร้างคอลัมน์ Email ขึ้นมาหากไม่มี แล้วใส่ค่า null ทั้งหมด

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

- ใช้ Table.SelectColumns ที่ต้นฉบับเพื่อ drop คอลัมน์ที่ไม่ต้องการทันที ก่อน transform ต่อ ทำให้ query เร็วกว่า

- โหลด data ครั้งแรก ใช้ Table.SelectColumns เหมือนเลือกคอลัมน์ใน load option - ประหยัด memory และ runtimes

- หากคอลัมน์อาจขาด ในบางครั้ง อย่าลืม MissingField.UseNull เพื่อหลีกเลี่ยง unexpected errors

- ลำดับคอลัมน์ที่เราระบุจะเป็นลำดับสุดท้าย ถ้าต้องจัดเรียงใหม่ ใช้ Table.SelectColumns ที่ก่อนสุด

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

**Q: จะลดจำนวนคอลัมน์ได้ไหม? ต้องทำอะไร?**

ใช่ Table.SelectColumns นั่นแหละ - ระบุชื่อคอลัมน์ที่ต้องการเท่านั้น คอลัมน์ไม่อยู่ในรายการจะถูก drop อัตโนมัติ

**Q: ต่างกับ Table.RemoveColumns ยังไง?**

Table.SelectColumns ระบุ keep ไหนแบบ whitelist (เก็บแค่ที่ระบุ), Table.RemoveColumns ระบุ remove ไหนแบบ blacklist (ลบของที่ระบุ) - ผลลัพธ์อาจเหมือนกันแต่การ think ต่างกัน

**Q: ลำดับคอลัมน์ในผลลัพธ์จากที่ไหน?**

จากลำดับใน columns parameter นั่นเอง - ถ้า list {"Name", "ID"} จะ Name อยู่ซ้าย ID อยู่ขวา ไม่ได้ตามตารางต้นฉบับ

**Q: เกิด error ว่า 'column not found' เพราะไง?**

ชื่อคอลัมน์พิมพ์ผิด หรือคอลัมน์ไม่มีจริง - เช็คชื่อให้ถูก case-sensitive หรือเพิ่ม MissingField.UseNull ถ้าคอลัมน์บางอย่างอาจขาด

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

- [Table.RemoveColumns – ลบคอลัมน์ที่ไม่ต้องการจาก table](https://www.thepexcel.com/functions/power-query/table-functions/table-removecolumns/)
- [Table.ReorderColumns – จัดเรียงลำดับคอลัมน์ใหม่](https://www.thepexcel.com/functions/power-query/table-functions/table-reordercolumns/)
- [Table.RenameColumns – เปลี่ยนชื่อคอลัมน์ในตาราง](https://www.thepexcel.com/functions/power-query/table-functions/table-renamecolumns/)
- [Table.FromRecords – สร้างตารางจากรายการ Record](https://www.thepexcel.com/functions/power-query/table-functions/table-fromrecords/)

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

- [Microsoft Learn - Table.SelectColumns](https://learn.microsoft.com/en-us/powerquery-m/table-selectcolumns) _(official)_
- [Microsoft Learn - MissingField options](https://learn.microsoft.com/en-us/powerquery-m/missingfield-type) _(official)_

---

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