---
title: Record.Field – ดึงค่า Field จาก Record
url: https://www.thepexcel.com/functions/power-query/record-functions/record-field/
type: function-explainer
program: Power Query
syntax: "Record.Field(record as record, field as text) as any"
date: 2025-12-03
updated: 2025-12-25
scores:
  popularity: 6
  difficulty: 3
  usefulness: 6
---

# Record.Field – ดึงค่า Field จาก Record

> Record.Field ดึงค่าของฟิลด์ที่ระบุจากบันทึก (record) โดยใช้ชื่อฟิลด์เป็นข้อความ ต่างจาก Record.Field

## คำอธิบาย

Record.Field ดึงค่าของฟิลด์ที่ระบุจากบันทึก (record) โดยใช้ชื่อฟิลด์เป็นข้อความ ต่างจาก Record.FieldOrDefault ตรงที่จะเกิดข้อผิดพลาดหากฟิลด์ไม่พบ

## Syntax

```excel
Record.Field(record as record, field as text) as any
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| record | Yes | record |  | Record ที่ต้องการดึงค่า |
| field | Yes | text |  | ชื่อ Field ที่ต้องการดึงค่า (เป็น Text) |

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

### ดึงค่าด้วยชื่อ Field จากตัวแปร

เมื่อชื่อ Field ที่ต้องการดึงถูกเก็บอยู่ในตัวแปร หรือมาจากการคำนวณ (Dynamic Field Access)

### เข้าถึง Record ใน List

ใช้ร่วมกับ List.Transform เพื่อดึงค่า Field จาก List ของ Record

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ดึงค่าพื้นฐาน

```excel
Record.Field([CustomerID = 1, Name = "Bob"], "Name")
```

**ผลลัพธ์:** `"Bob"`

ดึงค่าของ Field "Name" ออกมา เพราะเราบอกชัดเจนว่าต้องการค่า "Name" ฟังก์ชันจึงส่งกลับข้อความ Bob

### 2. ตัวอย่างที่ 2: ใช้ชื่อ Field ภาษาไทย

```excel
Record.Field([ชื่อ = "สมชาย", อายุ = 30], "ชื่อ")
```

**ผลลัพธ์:** `"สมชาย"`

รองรับชื่อ Field ภาษาไทยได้ไม่มีปัญหา ส่วนตัวผมใช้เป็นประจำทำให้รหัสอ่านเข้าใจง่ายขึ้น

### 3. ตัวอย่างที่ 3: การดึงค่าแบบ Dynamic

```excel
let
    Source = [A=10, B=20, C=30],
    TargetField = "B",
    Result = Record.Field(Source, TargetField)
in
    Result
```

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

ใช้ตัวแปร TargetField เก็บชื่อ Field ที่ต้องการดึงค่า ทำให้สามารถเปลี่ยนชื่อ Field ได้ตามต้องการ (Dynamic) นี่คือจุดเด่นหลักของ Record.Field

### 4. ตัวอย่างที่ 4: ใช้กับ JSON Data

```excel
let
    JsonData = Json.Document("{\"id\": 101, \"status\": \"Active\"}"),
    Status = Record.Field(JsonData, "status")
in
    Status
```

**ผลลัพธ์:** `"Active"`

เมื่อ JSON ถูก Parse เป็น Record จะได้ข้อมูลที่เป็น Field ต่างๆ Record.Field ช่วยดึงค่าจาก Field ที่กำหนดออกมาได้สะดวก

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

- ผมแนะนำให้ใช้ Record.Field เมื่อแน่ใจว่าฟิลด์มีอยู่จริง เพราะจะจับ Error ถ้ามีปัญหา ง่ายต่อ Debug

- ถ้าข้อมูลมาจากภายนอก (API, Excel, CSV) ให้ใช้ Record.FieldOrDefault ทุกครั้ง ผมเคยสดุดีเพราะลืมทำแบบนี้

- ชื่อฟิลด์ต้องเป็นข้อความสัตย์ ถ้าต้องการแบบ dynamic ให้สร้างตัวแปรก่อน แล้วส่งเข้า Record.Field ดีกว่า

- ส่วนตัวผม ผมชอบใช้ Record.Field ร่วมกับ try-catch เมื่อต้องทำงานกับข้อมูล JSON ที่โครงสร้างไม่แน่นอน

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

**Q: ต่างจาก [FieldName] อย่างไร?**

ผมเห็นบ่อยที่คนสับสน Record.Field ยืดหยุ่นกว่าเพราะรับชื่อฟิลด์เป็นข้อความ (dynamic) ส่วน [FieldName] ต้องเขียนชื่อตายตัวในสูตร ถ้าต้องการเปลี่ยนชื่อฟิลด์ตามเงื่อนไข Record.Field จึงเหมาะกว่า

**Q: ถ้าไม่เจอ Field จะเกิดอะไรขึ้น?**

โปรแกรมจะโยน Error ชื่อ 'The field ... of the record wasn't found.' ออกมา ผมเลยแนะนำให้ใช้ try-catch หรือเปลี่ยนมาใช้ Record.FieldOrDefault ถ้าไม่แน่ใจว่าฟิลด์มีหรือไม่

**Q: ต่างจาก Record.FieldOrDefault อย่างไร?**

Record.Field โยน Error ถ้าฟิลด์หายไป ส่วน Record.FieldOrDefault ส่งกลับค่า null หรือค่าตัวอักษร (default) แทน ผมแนะนำให้ใช้ Record.FieldOrDefault เมื่อข้อมูลมาจากแหล่งที่ไม่แน่ใจว่ามีฟิลด์ครบหรือไม่

**Q: สามารถดึง Field หลาย ๆ ตัวพร้อมกันได้ไหม?**

ได้แต่ต้องเรียก Record.Field หลายครั้ง ผมแนะนำให้ใช้ Record.ToList ถ้าต้องการค่าทั้งหมด หรือใช้ let...in เพื่อเก็บค่าแต่ละ Field ไว้ตัวแปรแต่ละอัน

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

- [Record.FieldOrDefault – ดึงค่า Record แบบปลอดภัย](https://www.thepexcel.com/functions/power-query/record-functions/record-fieldordefault/)
- [Record.HasFields – ตรวจสอบว่ามี Field ที่ระบุหรือไม่](https://www.thepexcel.com/functions/power-query/record-functions/record-hasfields/)
- [Record.RemoveFields – Remove fields from a record](https://www.thepexcel.com/functions/power-query/record-functions/record-removefields/)
- [Record.SelectFields – เลือก Field ที่ต้องการจาก Record](https://www.thepexcel.com/functions/power-query/record-functions/record-selectfields/)
- [Record.AddField – Add a field to a Power Query record](https://www.thepexcel.com/functions/power-query/record-functions/record-addfield/)
- [Table.Column – ดึงข้อมูลคอลัมน์จากตาราง](https://www.thepexcel.com/functions/power-query/table-functions/table-column/)

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

- [Microsoft Learn: Record.Field](https://learn.microsoft.com/en-us/powerquery-m/record-field) _(official)_
- [PowerQuery.how](https://powerquery.how/record-field/) _(article)_
- [Microsoft Learn: Record Functions](https://learn.microsoft.com/en-us/powerquery-m/record-functions) _(official)_

---

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