---
title: SAMPLE – ฟังก์ชัน DAX
url: https://www.thepexcel.com/functions/dax/statistical/sample-dax/
type: function-explainer
program: DAX
syntax: "SAMPLE(<Size>, <Table>, <OrderBy>, [<Order>])"
date: 2025-12-15
updated: 2025-12-17
scores:
  popularity: 4
  difficulty: 5
  usefulness: 4
---

# SAMPLE – ฟังก์ชัน DAX

> ส่งกลับตัวอย่างข้อมูลสม่ำเสมอจากตาราง

## คำอธิบาย

SAMPLE ส่งกลับตัวอย่างข้อมูลที่เลือกอย่างสม่ำเสมอจากตาราง โดยเลือกแถวแบบกระจายไปทั่วตามลำดับที่ระบุ ผลลัพธ์คงที่ (Deterministic) เมื่อเรียกด้วยอาร์กิวเมนต์เดียวกัน ใช้สำหรับสร้างตัวอย่างข้อมูลเพื่อการวิเคราะห์หรือ Reporting โดยได้ตัวแทนข้อมูลจริงอย่างดี

## Syntax

```excel
SAMPLE(&lt;Size&gt;, &lt;Table&gt;, &lt;OrderBy&gt;, [&lt;Order&gt;])
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| Size | Yes | integer | ไม่มี | จำนวนแถวที่ต้องการในตัวอย่าง |
| Table | Yes | table | ไม่มี | ตารางที่จะสุ่มตัวอย่าง |
| OrderBy | Yes | column | ไม่มี | คอลัมน์ที่ใช้เรียงลำดับ |

## ตัวอย่าง

### 1. สุ่ม 10 แถวแบบสม่ำเสมอ

```excel
SAMPLE(10, Customers, Customers[ID], ASC)
```

**ผลลัพธ์:** `ตาราง 10 แถว`

เลือก 10 แถวจากข้อมูลลูกค้าทั้งหมด เรียงตาม ID เพื่อให้ได้ตัวแทนข้อมูลสม่ำเสมอ

### 2. สร้าง Representative Sample

```excel
SAMPLE(100, Sales, Sales[Date], ASC)
```

**ผลลัพธ์:** `ตาราง 100 แถว`

เลือก 100 ธุรกรรมขายจากทั้งหมด เรียงตามวันที่ ได้ตัวแทนทั่ว ๆ ไปตลอดเวลา

### 3. Sampling สำหรับการทดลอง

```excel
SAMPLE(50, Products, Products[Sales], DESC)
```

**ผลลัพธ์:** `ตาราง 50 แถว`

เลือก 50 สินค้า เรียงตามยอดขายลดลง ได้สินค้าตัวแทนจากต่ำ ปานกลาง สูง

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

⭐ สำหรับ Data Sampling | 💡 Deterministic - ผลลัพธ์คงที่ | 🔗 ต้องมี OrderBy

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

**Q: SAMPLE ต้องมี OrderBy ไหม**

ใช่ OrderBy จำเป็น เพื่อระบุว่าจะเลือกแถวอย่างไร ส่วน Order ทางขึ้น/ลง ไม่บังคับ

**Q: ผลลัพธ์คงที่ไหม**

ใช่ SAMPLE Deterministic - เรียกหลายครั้งด้วยอาร์กิวเมนต์เดียวกันได้ผลเดียวกัน

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

- [FILTER – กรองตารางด้วยเงื่อนไขที่ซับซ้อน (Iterator Function)](https://www.thepexcel.com/functions/dax/filter/filter-dax/)
- [TOPN – คืนตาราง Top N ตามนิพจน์การเรียงลำดับ](https://www.thepexcel.com/functions/dax/table-manipulation/topn-dax/)
- sort-dax

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

- [DAX.Guide: SAMPLE](https://dax.guide/sample/) _(documentation)_
- [Microsoft Learn](https://learn.microsoft.com/en-us/dax/function/sample) _(documentation)_

---

_Source: [https://www.thepexcel.com/functions/dax/statistical/sample-dax/](https://www.thepexcel.com/functions/dax/statistical/sample-dax/)_
