---
title: Value.Type – ตรวจสอบชนิดข้อมูลของค่า
url: https://www.thepexcel.com/functions/power-query/value-functions/value-type/
type: function-explainer
program: Power Query
syntax: = Value.Type(value as any) as type
date: 2025-12-03
updated: 2025-12-25
scores:
  popularity: 5
  difficulty: 5
  usefulness: 5
---

# Value.Type – ตรวจสอบชนิดข้อมูลของค่า

> Value.Type คืนค่า Type ของข้อมูลที่กำหนด ช่วยตรวจสอบว่าเป็น number, text, date, table, list หรือชนิด

## คำอธิบาย

Value.Type คืนค่า Type ของข้อมูลที่กำหนด ช่วยตรวจสอบว่าเป็น number, text, date, table, list หรือชนิดอื่นๆ มีประโยชน์มากสำหรับ data validation และการเขียน dynamic functions

## Syntax

```excel
= Value.Type(value as any) as type
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| value | Yes | any |  | ค่าหรือข้อมูลใดๆ ที่ต้องการตรวจสอบชนิด เป็น any type ก็ได้ (number, text, list, table, record, null, ฯลฯ) |

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

### ตรวจสอบชนิดข้อมูล

เช็คว่าค่าในคอลัมน์นี้เป็นตัวเลขหรือข้อความ เพื่อเลือกวิธีการจัดการที่เหมาะสม

### สร้าง Custom Function ที่ยืดหยุ่น

เขียนฟังก์ชันที่ทำงานต่างกันตามชนิดข้อมูลที่รับเข้ามา (Polymorphic Function)

## ตัวอย่าง

### 1. ตรวจสอบตัวเลข

```excel
Value.Type(123)
```

**ผลลัพธ์:** `type number`

ค่า 123 เป็นตัวเลข ดังนั้นคืนค่า type number กลับมา ซึ่งเป็นชนิดข้อมูลตัวเลขพื้นฐาน

### 2. ตรวจสอบข้อความ

```excel
Value.Type("Hello World")
```

**ผลลัพธ์:** `type text`

ค่า "Hello World" เป็นข้อความหรือสตริง ดังนั้นคืนค่า type text ซึ่งเป็นชนิดข้อมูลข้อความ

### 3. ตรวจสอบวันที่

```excel
Value.Type(#date(2025, 12, 25))
```

**ผลลัพธ์:** `type date`

ค่า #date(2025, 12, 25) เป็นวันที่ ดังนั้นคืนค่า type date ซึ่งเป็นชนิดข้อมูลวันที่

### 4. ตรวจสอบ List

```excel
Value.Type({1, 2, 3})
```

**ผลลัพธ์:** `type list`

ค่า {1, 2, 3} เป็นรายการหรือลิสต์ ดังนั้นคืนค่า type list ซึ่งเป็นชนิดข้อมูลแบบรายการ

### 5. ตรวจสอบ Record

```excel
Value.Type([Name = "Sira", Age = 30])
```

**ผลลัพธ์:** `type record`

ค่า [Name = "Sira", Age = 30] เป็นเรคคอร์ด ดังนั้นคืนค่า type record ซึ่งเป็นชนิดข้อมูลแบบเรคคอร์ด

### 6. ตรวจสอบ null value

```excel
Value.Type(null)
```

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

ค่า null เป็น null type ดังนั้นคืนค่า type null

### 7. ตรวจสอบ logical (true/false)

```excel
Value.Type(true)
```

**ผลลัพธ์:** `type logical`

ค่า true เป็น logical (boolean) ดังนั้นคืนค่า type logical

### 8. ใช้กับ if statement เพื่อ convert ข้อมูล

```excel
let
    Input = "12345",
    CheckType = Value.Type(Input),
    Result = if CheckType = type text then Number.From(Input) else Input
in
    Result
```

**ผลลัพธ์:** `12345 (แปลงเป็น number)`

ตรวจสอบว่า Input เป็น text หรือไม่ ถ้าใช่จะแปลงเป็น number ด้วย Number.From

### 9. สร้าง custom function ที่ handle ได้หลายชนิด

```excel
let
    MyFunction = (value) =>
        let
            TypeCheck = Value.Type(value)
        in
            if TypeCheck = type number then "It's a number: " & Text.From(value)
            else if TypeCheck = type text then "It's text: " & value
            else if TypeCheck = type list then "It's a list with " & Text.From(List.Count(value)) & " items"
            else "Unknown type"
    
    Test1 = MyFunction(42),
    Test2 = MyFunction("Hello"),
    Test3 = MyFunction({1, 2, 3})
in
    {Test1, Test2, Test3}
```

**ผลลัพธ์:** `{"It's a number: 42", "It's text: Hello", "It's a list with 3 items"}`

สร้าง function ที่ accept input ได้หลายชนิด แล้วทำ different action ขึ้นอยู่กับชนิดของ input ที่รับเข้ามา

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

- ผมแนะนำให้ใช้ Value.Type เมื่อต้องเขียน error handling ดี ๆ เพื่อให้ code ทำงานได้ถูกต้องแม้ว่า input มาจากหลายแหล่ง

- เมื่อทำ data transformation ให้ check type หลังจาก Text.From หรือ Number.From เพื่อให้แน่ใจว่า conversion ประสบความสำเร็จ ผมเคยพลาด type check เพราะ Number.From("abc") ให้ error

- ใช้ Value.Type ร่วมกับ if...then...else...else ได้ดี ถ้าต้องจัดการ input ได้หลายชนิด ช่วยให้ code readable และ maintainable มากขึ้น

- ส่วนตัวผมชอบใช้ Value.Type ในการเขียน functions ที่ accept list of any type แล้ว transform แต่ละ element ตามชนิดของมัน

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

**Q: Value.Type กับ Value.Is ต่างกันอย่างไร?**

Value.Type คืนค่า type ที่เป็น actual type ของ value ออกมา เช่น type number, type text ส่วน Value.Is คืนค่า true/false เพื่อตรวจสอบว่า value เป็น type ที่ระบุหรือไม่ เช่น Value.Is(123, type number) = true ผมแนะนำให้ใช้ Value.Type เมื่อต้องรู้ว่า value เป็นชนิดอะไร และใช้ Value.Is เมื่อต้องเช็คว่า value เป็น specific type ที่คาด หรือไม่

**Q: Value.Type(null) คืนค่าอะไร?**

Value.Type(null) คืนค่า type null กลับมา เป็น type ที่ represent ค่า null หรือค่าว่าง ผมเคยใช้อันนี้ในการตรวจสอบว่า query กลับค่ามา null จากการ process ข้อมูล

**Q: ทำไมต้องใช้ Value.Type ถ้ามี Value.Is?**

Value.Type มีประโยชน์เมื่อต้องทำสิ่งที่ต่างๆ ขึ้นอยู่กับชนิดข้อมูล (multiple conditions) เพราะสามารถ store type ไว้ในตัวแปร แล้ว compare ได้หลายครั้ง ส่วน Value.Is นั้นเป็น shorthand สำหรับการเช็คชนิด specific เพียง 1 ครั้ง ผมชอบใช้ Value.Type ใน custom functions ที่ต้องรองรับ input หลายชนิด

**Q: สามารถใช้ Value.Type ได้กับ table หรือไม่?**

ได้ครับ Value.Type ใช้ได้กับ table Type คืนค่า type table กลับมา แต่ถ้าต้องรู้ว่า table มี column อะไรบ้าง หรือ schema เป็นอย่างไร ต้องใช้ Table.Schema() แทน

**Q: Value.Type มี Performance issue ไหม?**

Value.Type นั้นเป็น lightweight operation ไม่มี performance issue ผมใช้มันในการ validate data แบบ row-by-row ก็ไม่เห็นปัญหา แต่ถ้าต้องเช็ค type ของข้อมูลหลาย millions rows อาจจะควร cache type check ขั้นบน level ของ table schema แทนจะดีกว่า

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

- [Value.Is](https://www.thepexcel.com/functions/power-query/value-functions/value-is/)
- [Type.Is](https://www.thepexcel.com/functions/power-query/type-functions/type-is/)
- [Value.As](https://www.thepexcel.com/functions/power-query/value-functions/value-as/)

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

- [Microsoft Learn: Value.Type](https://learn.microsoft.com/en-us/powerquery-m/value-type) _(official)_
- [Microsoft Learn: Value.Is](https://learn.microsoft.com/en-us/powerquery-m/value-is) _(official)_
- [PowerQuery.how: Type Checking](https://powerquery.how) _(article)_

---

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