ตัวอย่างที่ 1: ตรวจสอบตัวเลข
=Value.Type(123)
type number
คืนค่าชนิดข้อมูล (Type) ของค่าที่กำหนด
Value.Type จะคืนค่า Type ของ Input ที่รับเข้ามา เช่น type text, type number, type table, หรือ type list มีประโยชน์ในการตรวจสอบชนิดข้อมูลก่อนทำการแปลงหรือคำนวณ
=Value.Type(value as any) as type
=Value.Type(value as any) as type
| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| value | any | Yes | ค่าที่ต้องการตรวจสอบชนิดข้อมูล |
เช็คว่าค่าในคอลัมน์นี้เป็นตัวเลขหรือข้อความ เพื่อเลือกวิธีการจัดการที่เหมาะสม
เขียนฟังก์ชันที่ทำงานต่างกันตามชนิดข้อมูลที่รับเข้ามา (Polymorphic Function)
=Value.Type(123)
type number
=Value.Type("Hello")
type text
=if Value.Type([Column1]) = type number then "Number" else "Other"
"Number" หรือ "Other"
ได้ type null ครับ
Value.Type คืนค่า Type ออกมาเลย ส่วน Value.Is คืนค่า true/false ว่าใช่นั้นไหม (เช่น Value.Is(123, type number) = true)
ฟังก์ชัน Value.Type ใน Power Query ใช้สำหรับตรวจสอบชนิดข้อมูล (Data Type) ของค่าที่กำหนด ว่าเป็น Text, Number, Date หรือชนิดอื่นๆ