---
title: List.FirstN – ดึงสมาชิก N ตัวแรกจาก List
url: https://www.thepexcel.com/functions/power-query/list-functions/list-firstn/
type: function-explainer
program: Power Query
syntax: "List.FirstN(list as list, countOrCondition as any) as any"
date: 2025-12-03
updated: 2025-12-24
scores:
  popularity: 6
  difficulty: 3
  usefulness: 6
---

# List.FirstN – ดึงสมาชิก N ตัวแรกจาก List

> List.FirstN จะคืน List ใหม่ที่มีสมาชิก N ตัวแรกจาก List ต้นฉบับ สามารถระบุจำนวน N ด้วยตัวเลข หรือกำห

## คำอธิบาย

List.FirstN จะคืน List ใหม่ที่มีสมาชิก N ตัวแรกจาก List ต้นฉบับ สามารถระบุจำนวน N ด้วยตัวเลข หรือกำหนดเป็นฟังก์ชันเงื่อนไขเพื่อให้ดึงสมาชิกที่ตรงเงื่อนไขจากจุดเริ่มต้นไปเรื่อยๆ จนกว่าเงื่อนไขจะไม่เป็นจริง

## Syntax

```excel
List.FirstN(list as list, countOrCondition as any) as any
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| list | Yes | list |  | List ที่ต้องการดึงสมาชิก |
| countOrCondition | Yes | number \| function |  | จำนวนสมาชิกที่ต้องการดึง (number) หรือฟังก์ชันเงื่อนไขแบบ each (เช่น each _ > 5) |

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

### เลือก 5 อันดับแรก

เลือกรายการสินค้า 5 อันดับแรกที่มีมูลค่าสูงสุด (ใช้ List.Sort ก่อน)

### ตัดหัวตารางที่ไม่ต้องการ

ถ้าข้อมูลมีบรรทัดที่ไม่ใช่หัวตาราง สามารถใช้ List.Skip หรือ List.FirstN มาช่วย

### แสดงตัวอย่างข้อมูล

ดึงข้อมูลเพียงไม่กี่รายการแรกมาแสดงเพื่อตรวจสอบความถูกต้องเบื้องต้น

## ตัวอย่าง

### 1. ดึง N ตัวแรกด้วยตัวเลข

```excel
let
    Numbers = {1, 2, 3, 4, 5},
    FirstTwo = List.FirstN(Numbers, 2)
in
    FirstTwo
```

**ผลลัพธ์:** `{1, 2}`

ดึง 2 สมาชิกแรกจาก {1, 2, 3, 4, 5}

### 2. ดึงสมาชิกตามเงื่อนไข (each)

```excel
let
    Numbers = {10, 20, 5, 30},
    FirstGreaterThan5 = List.FirstN(Numbers, each _ > 5)
in
    FirstGreaterThan5
```

**ผลลัพธ์:** `{10, 20}`

ดึงสมาชิกจากหน้าตราบใดที่ยังมากกว่า 5 หยุดตอนเจอ 5

### 3. ดึงหัวข้อจากข้อมูลที่เป็น Text

```excel
let
    TextLines = {"Header: Product", "Header: Price", "Data: Apple", "Data: 100"},
    Headers = List.FirstN(TextLines, each Text.StartsWith(_, "Header"))
in
    Headers
```

**ผลลัพธ์:** `{"Header: Product", "Header: Price"}`

ดึงบรรทัดทั้งหมดที่ขึ้นต้นด้วย 'Header' จนกว่าจะเจอ 'Data'

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

- ใช้ List.FirstN กับ each condition เพื่อหยุดประมวลผลเร็ว ประหยัด resource

- ถ้า List ว่าง (ไม่มีสมาชิก) มันจะคืน List ว่างไม่มี error

- เหมาะใช้กับ sampling data ตัวอย่าง หรือตรวจสอบค่าตัวแรกที่ตรงเงื่อนไข

- ใช้ร่วมกับ List.Drop ได้ เพื่อตัดหัวตัวท้ายลิสต์

- เวลาใช้เงื่อนไข ต้องเรียงลำดับ List ให้ถูกก่อน เพราะมันหยุดตรงแรกที่ไม่ตรง

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

**Q: List.FirstN กับ List.First ต่างกันอย่างไร?**

List.First ดึงแค่สมาชิก 1 ตัวแรก (คืนค่าเดี่ยว) ส่วน List.FirstN ดึง N ตัวแรก (คืนค่า List)

**Q: ถ้าระบุ N มากกว่าจำนวนสมาชิกใน List จะเกิดอะไร?**

มันจะคืน List ทั้งหมด ไม่มี error ถ้า List มี 3 ตัว แล้วขอ 10 ตัว มันจะคืน 3 ตัวทั้งหมด

**Q: แบบเงื่อนไขหยุดเร็วกว่าแบบนับจำนวนไหม?**

ใช่ แบบเงื่อนไขหยุดทีแรกที่เจอค่าไม่ตรง ส่วนแบบนับต้องนับครบ N ตัว

**Q: ทำไมไม่ใช้ List.Select แล้วอย่างไร?**

List.Select ดึงทั้ง List ที่ตรงเงื่อนไข ส่วน List.FirstN หยุดตรงแรกที่ไม่ตรง ประหยัด performance

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

- [List.First – ดึงสมาชิกตัวแรกจาก List](https://www.thepexcel.com/functions/power-query/list-functions/list-first/)
- [List.LastN – ดึงสมาชิก N ตัวท้ายจาก List](https://www.thepexcel.com/functions/power-query/list-functions/list-lastn/)
- [List.Select – เลือกสมาชิกจาก List ตามเงื่อนไข](https://www.thepexcel.com/functions/power-query/list-functions/list-select/)
- [List.Skip – ข้ามสมาชิก N ตัวแรกจาก List](https://www.thepexcel.com/functions/power-query/list-functions/list-skip/)
- [List.Alternate – เลือกและข้ามสมาชิกใน List สลับกัน](https://www.thepexcel.com/functions/power-query/list-functions/list-alternate/)

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

- [Microsoft Learn: List.FirstN](https://learn.microsoft.com/en-us/powerquery-m/list-firstn) _(official)_
- [PowerQuery.how](https://powerquery.how/list-firstn/) _(article)_

---

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