ตัวอย่างที่ 1: ตรวจสอบการขึ้นต้น
=Text.StartsWith("apple", "app")
true
เช็คว่าข้อความหลักขึ้นต้นด้วยข้อความย่อยที่กำหนดหรือไม่
Text.StartsWith จะคืนค่า true หาก text หลักขึ้นต้นด้วย substring ที่กำหนด และคืนค่า false หากไม่ตรงกัน สามารถระบุ Comparer เพื่อกำหนดว่าจะให้ตรวจสอบแบบ Case Sensitive หรือ Case Insensitive ได้
=Text.StartsWith(text as nullable text, substring as text, optional comparer as nullable function) as nullable logical
=Text.StartsWith(text as nullable text, substring as text, optional comparer as nullable function) as nullable logical
| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| text | text | Yes | ข้อความหลักที่ต้องการตรวจสอบ | |
| substring | text | Yes | ข้อความย่อยที่ต้องการตรวจสอบการขึ้นต้น | |
| comparer | function | Optional | null | ฟังก์ชัน Comparer สำหรับการเปรียบเทียบ เช่น Comparer.OrdinalIgnoreCase |
เลือกเฉพาะรายการสินค้าที่รหัสขึ้นต้นด้วย "PROD" หรือ "SKU"
ถ้าข้อความในคอลัมน์ขึ้นต้นด้วย "Fruits" ให้จัดอยู่ในหมวดหมู่ผลไม้
=Text.StartsWith("apple", "app")
true
=Text.StartsWith("banana", "app")
false
=Text.StartsWith("Apple", "app", Comparer.OrdinalIgnoreCase)
true
เป็น Case Sensitive ครับ เช่น Text.StartsWith(“Apple”, “app”) จะได้ false ถ้าต้องการไม่สนใจ Case ต้องใช้ Comparer.OrdinalIgnoreCase
ฟังก์ชัน Text.StartsWith ใน Power Query ใช้สำหรับตรวจสอบว่าข้อความหลัก ขึ้นต้นด้วยข้อความย่อย (Substring) ที่กำหนดหรือไม่ โดยจะคืนค่าเป็น true หากใช่ และ false หากไม่ใช่