---
title: List.Last – คืนค่าสมาชิกตัวสุดท้ายของ List
url: https://www.thepexcel.com/functions/power-query/list-functions/list-last/
type: function-explainer
program: Power Query
syntax: "List.Last(list as list, optional defaultValue as any) as any"
date: 2025-12-03
updated: 2025-12-26
scores:
  popularity: 6
  difficulty: 2
  usefulness: 6
---

# List.Last – คืนค่าสมาชิกตัวสุดท้ายของ List

> List.Last คืนค่าสมาชิกตัวสุดท้ายของ List หรือค่า Default ถ้า List ว่าง

## คำอธิบาย

List.Last คืนค่าสมาชิกตัวสุดท้ายของ List หรือค่า Default ถ้า List ว่าง

## Syntax

```excel
List.Last(list as list, optional defaultValue as any) as any
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| list | Yes | list |  | List ที่ต้องการดึงสมาชิกตัวสุดท้าย |
| defaultValue | No | any | null | ค่าที่จะคืนกลับมาหาก List ว่างเปล่า |

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

### ดึงข้อมูลล่าสุด (กรณีเรียงเก่าไปใหม่)

หาก List เรียงลำดับจากเก่าไปใหม่ สามารถใช้ List.Last เพื่อดึงข้อมูลล่าสุด (ท้ายสุด) ออกมา

### ค้นหาตัวปิดท้าย

ใช้ดึงตัวอักษรสุดท้าย หรือข้อมูลปิดท้ายของชุดข้อมูล

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ดึงค่าตัวสุดท้ายจาก List ปกติ

```excel
List.Last({1, 2, 3})
```

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

คืนค่าสมาชิกตัวสุดท้ายของ List คือ 3

### 2. ตัวอย่างที่ 2: ดึงค่าจาก List ว่างเปล่า (ไม่ระบุ Default)

```excel
List.Last({})
```

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

เนื่องจาก List ว่างและไม่ได้ระบุค่า defaultValue จึงคืนค่า null

### 3. ตัวอย่างที่ 3: ดึงค่าจาก List ว่างเปล่า (ระบุ Default)

```excel
List.Last({}, -1)
```

**ผลลัพธ์:** `-1`

เนื่องจาก List ว่าง จึงคืนค่า defaultValue ที่ระบุไว้คือ -1

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

- ผมแนะนำให้ใช้ defaultValue เพื่อหลีกเลี่ยง null ที่ไม่คาดคิด โดยเฉพาะตอนทำ Data Cleaning

- ส่วนตัวผม ผมสังเกตว่า List.Last เร็วกว่า List.Range + List.Count สำหรับ List ขนาดใหญ่

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

**Q: List.Last ต่างจาก List.LastN อย่างไร?**

List.Last คืนค่า 'สมาชิกตัวเดียว' ในขณะที่ List.LastN คืนค่าเป็น 'List' ของสมาชิก N ตัวสุดท้าย

**Q: ถ้าสมาชิกตัวสุดท้ายเป็น null จะได้ค่าอะไร?**

จะได้ค่า null (ที่เป็นข้อมูลจริง ไม่ใช่ null ที่เกิดจาก List ว่าง)

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

- [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.Single – คืนค่าสมาชิกเดี่ยว](https://www.thepexcel.com/functions/power-query/list-functions/list-single/)
- [Table.Last – ดึงข้อมูลแถวสุดท้าย](https://www.thepexcel.com/functions/power-query/table-functions/table-last/)

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

- [Microsoft Learn: List.Last](https://learn.microsoft.com/en-us/powerquery-m/list-last) _(official)_

---

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