---
title: List.Alternate – เลือกและข้ามสมาชิกใน List สลับกัน
url: https://www.thepexcel.com/functions/power-query/list-functions/list-alternate/
type: function-explainer
program: Power Query
syntax: "List.Alternate(list as list, count as number, optional repeatInterval as nullable number, optional offset as nullable number) as list"
date: 2025-12-03
updated: 2025-12-17
scores:
  popularity: 5
  difficulty: 4
  usefulness: 5
---

# List.Alternate – เลือกและข้ามสมาชิกใน List สลับกัน

> เลือกและข้ามสมาชิกใน List สลับกัน

## คำอธิบาย

List.Alternate ใช้สร้าง List ใหม่โดยการสลับระหว่างการข้าม (Skip) และการเก็บ (Take) สมาชิกจาก List ต้นฉบับ สามารถกำหนดจำนวนที่จะข้าม จำนวนที่จะเก็บ และจุดเริ่มต้นได้

## Syntax

```excel
List.Alternate(list as list, count as number, optional repeatInterval as nullable number, optional offset as nullable number) as list
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| list | Yes | list |  | List ต้นฉบับที่ต้องการประมวลผล |
| count | Yes | number |  | จำนวนสมาชิกที่จะ 'ข้าม' (Skip) ในแต่ละรอบ |
| repeatInterval | No | number | null | จำนวนสมาชิกที่จะ 'เก็บ' (Keep) ในระหว่างช่วงที่ข้าม (ถ้าไม่ระบุ จะเก็บส่วนที่เหลือทั้งหมดหลังจากข้ามครั้งแรก) |
| offset | No | number | 0 | จำนวนสมาชิกที่จะข้ามก่อนเริ่มกระบวนการสลับ (Offset เริ่มต้น) |

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

### เลือกเฉพาะบรรทัดคู่หรือคี่

ใช้เลือกข้อมูลทุกๆ 2 บรรทัด เช่น เลือกเฉพาะบรรทัดที่ 1, 3, 5... หรือ 2, 4, 6...

### การสุ่มตัวอย่างแบบเป็นระบบ

เลือกข้อมูลบางส่วนมาตรวจสอบ เช่น เก็บ 5 รายการ ข้าม 95 รายการ เพื่อสุ่มตรวจ 5% ของข้อมูลทั้งหมด

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ข้ามตัวแรก (Skip 1, Keep Rest)

```excel
List.Alternate({1..10}, 1)
```

**ผลลัพธ์:** `{2, 3, 4, 5, 6, 7, 8, 9, 10}`

ข้ามสมาชิก 1 ตัวแรก (เลข 1) แล้วเก็บที่เหลือทั้งหมด

### 2. ตัวอย่างที่ 2: เลือกเลขคู่ (Skip 1, Keep 1)

```excel
List.Alternate({1..10}, 1, 1)
```

**ผลลัพธ์:** `{2, 4, 6, 8, 10}`

เริ่มด้วยการข้าม 1 ตัว (เลข 1) เก็บ 1 ตัว (เลข 2) ข้าม 1 ตัว (เลข 3) เก็บ 1 ตัว (เลข 4) สลับไปเรื่อยๆ

### 3. ตัวอย่างที่ 3: เลือกเลขคี่ (Offset 1, Skip 1, Keep 1)

```excel
List.Alternate({1..10}, 1, 1, 1)
```

**ผลลัพธ์:** `{1, 3, 5, 7, 9}`

กำหนด Offset เป็น 1 คือให้เริ่มข้ามที่ตำแหน่ง Index 1 (ตัวที่ 2) ดังนั้นตัวที่ 1 (เลข 1) จะถูกเก็บไว้ก่อน แล้วค่อยเริ่มกระบวนการ (ข้าม 2, เก็บ 3, ข้าม 4...)

### 4. ตัวอย่างที่ 4: รูปแบบซับซ้อน (Offset 1, Skip 1, Keep 2)

```excel
List.Alternate({1..10}, 1, 2, 1)
```

**ผลลัพธ์:** `{1, 3, 4, 6, 7, 9, 10}`

Offset 1: เก็บตัวแรก (1)
จากนั้นเริ่มวนลูป: ข้าม 1 (2), เก็บ 2 (3, 4)
ข้าม 1 (5), เก็บ 2 (6, 7)
ข้าม 1 (8), เก็บ 2 (9, 10)

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

**Q: Offset เริ่มนับที่ 0 หรือ 1?**

ใน Power Query Offset จะเป็นการนับจำนวนตัวที่ 'ผ่านไป' (Skip) ดังนั้น Offset 1 หมายถึงข้ามตัวแรกไป (เริ่มกระบวนการที่ตัวที่ 2)

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

ถ้าไม่ใส่ repeatInterval ฟังก์ชันจะทำการข้ามแค่ครั้งเดียวตามจำนวน count แล้วเก็บสมาชิกที่เหลือทั้งหมด

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

- [List.Skip – ข้ามสมาชิก N ตัวแรกจาก List](https://www.thepexcel.com/functions/power-query/list-functions/list-skip/)
- [List.FirstN – ดึงสมาชิก N ตัวแรกจาก List](https://www.thepexcel.com/functions/power-query/list-functions/list-firstn/)
- [List.Range – ดึงช่วงของสมาชิกจาก List](https://www.thepexcel.com/functions/power-query/list-functions/list-range/)
- [List.Select – เลือกสมาชิกจาก List ตามเงื่อนไข](https://www.thepexcel.com/functions/power-query/list-functions/list-select/)
- [List.Repeat – ทำซ้ำ List หลายครั้ง](https://www.thepexcel.com/functions/power-query/list-functions/list-repeat/)

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

- [Microsoft Learn: List.Alternate](https://learn.microsoft.com/en-us/powerquery-m/list-alternate) _(Official Documentation)_

---

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