---
title: Text.NewGuid – สร้าง GUID ใหม่
url: https://www.thepexcel.com/functions/power-query/text-functions/text-newguid/
type: function-explainer
program: Power Query
syntax: Text.NewGuid() as text
date: 2025-12-04
updated: 2025-12-17
scores:
  popularity: 4
  difficulty: 2
  usefulness: 4
---

# Text.NewGuid – สร้าง GUID ใหม่

> สร้าง GUID สุ่มใหม่

## คำอธิบาย

Text.NewGuid ใช้สำหรับสร้าง GUID (Globally Unique Identifier) ใหม่ที่เป็นเอกลักษณ์ แต่ละครั้งที่เรียกจะสร้าง GUID ที่แตกต่างกัน ใช้สำหรับสร้างรหัสเฉพาะตัวที่ไม่ซ้ำ

## Syntax

```excel
Text.NewGuid() as text
```

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

### สร้างรหัสประจำตัวเฉพาะสำหรับระเบียนข้อมูล

สร้างรหัสประจำตัวเฉพาะสำหรับระเบียนข้อมูล

### สร้างคีย์อ้างอิง (Primary Key) สำหรับตาราง

สร้างคีย์อ้างอิง (Primary Key) สำหรับตาราง

### สร้าง ID สำหรับการติดตามข้อมูลและ logging

สร้าง ID สำหรับการติดตามข้อมูลและ logging

## ตัวอย่าง

### 1. สร้าง GUID ใหม่

```excel
Text.NewGuid()
```

**ผลลัพธ์:** `a1b2c3d4-e5f6-47a8-9b0c-1d2e3f4a5b6c`

สร้าง GUID แบบสุ่ม (ค่าจริงจะแตกต่างกันแต่ละครั้ง)

### 2. เพิ่มคอลัมน์ ID เฉพาะตัว

```excel
let Source = Table.AddColumn(Table, "ID", each Text.NewGuid()) in Source
```

**ผลลัพธ์:** `[ตารางกับ GUID ใน ID column]`

เพิ่มคอลัมน์ด้วย GUID เฉพาะตัวสำหรับแต่ละแถว โดยใช้ let...in structure

### 3. เก็บ GUID ในตัวแปร

```excel
let ID = Text.NewGuid() in ID
```

**ผลลัพธ์:** `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`

สร้างและเก็บ GUID ในตัวแปร

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

- [Guid.From – สร้าง GUID จากข้อความ](https://www.thepexcel.com/functions/power-query/text-functions/guid-from/)
- [Table.AddColumn – เพิ่มคอลัมน์ใหม่ด้วย Calculated Values](https://www.thepexcel.com/functions/power-query/table-functions/table-addcolumn/)

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

- [Microsoft Learn: Text.NewGuid](https://learn.microsoft.com/en-us/powerquery-m/text-newguid) _(Official Documentation)_

---

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