---
title: Record.HasFields – ตรวจสอบว่ามี Field ที่ระบุหรือไม่
url: https://www.thepexcel.com/functions/power-query/record-functions/record-hasfields/
type: function-explainer
program: Power Query
syntax: "Record.HasFields(record as record, fields as any) as logical"
date: 2025-12-03
updated: 2025-12-17
scores:
  popularity: 5
  difficulty: 3
  usefulness: 5
---

# Record.HasFields – ตรวจสอบว่ามี Field ที่ระบุหรือไม่

> เช็คว่ามี Field ไหม

## คำอธิบาย

ตรวจสอบว่า Record มี Field ที่ระบุหรือไม่

## Syntax

```excel
Record.HasFields(record as record, fields as any) as logical
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| record | Yes | record |  | Record ที่ต้องการตรวจสอบ |
| fields | Yes | any |  | ชื่อ Field (Text) หรือ List ของชื่อ Field ที่ต้องการตรวจสอบ |

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

### ตรวจสอบก่อนดึงค่า

ใช้ตรวจสอบว่ามี Field นั้นๆ อยู่จริงหรือไม่ ก่อนที่จะใช้ Record.Field เพื่อป้องกัน Error

### ตรวจสอบโครงสร้างข้อมูล

ใช้เช็คว่าข้อมูลที่นำเข้ามามีโครงสร้าง (Schema) ครบถ้วนตามที่ต้องการหรือไม่

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ตรวจสอบ Field เดียว

```excel
Record.HasFields([A=1, B=2], "A")
```

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

มี Field "A" อยู่ใน Record

### 2. ตัวอย่างที่ 2: ตรวจสอบหลาย Field พร้อมกัน

```excel
Record.HasFields([A=1, B=2, C=3], {"A", "B"})
```

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

มีทั้ง Field "A" และ "B" ครบถ้วน

### 3. ตัวอย่างที่ 3: กรณีไม่พบ Field

```excel
Record.HasFields([A=1], "Z")
```

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

ไม่มี Field "Z" ใน Record

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

- [Record.Field – ดึงค่า Field จาก Record](https://www.thepexcel.com/functions/power-query/record-functions/record-field/)
- [Record.FieldOrDefault – ดึงค่า Record แบบปลอดภัย](https://www.thepexcel.com/functions/power-query/record-functions/record-fieldordefault/)
- [Record.FieldNames – ดึงชื่อ Field ทั้งหมดจาก Record](https://www.thepexcel.com/functions/power-query/record-functions/record-fieldnames/)
- [Record.FieldCount – นับจำนวน Field ใน Record](https://www.thepexcel.com/functions/power-query/record-functions/record-fieldcount/)

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

- [Microsoft Learn: Record.HasFields](https://learn.microsoft.com/en-us/powerquery-m/record-hasfields) _(Official Documentation)_
- [PowerQuery.how](https://powerquery.how/record-hasfields/) _(guide)_

---

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