ตัวอย่างที่ 1: ค้นหาข้อความย่อย
=Text.Contains("apple", "pp")
true
เช็คว่าข้อความหลักมีข้อความย่อยที่กำหนดหรือไม่
Text.Contains จะคืนค่า true หาก substring ที่กำหนดพบใน text หลัก และคืนค่า false หากไม่พบ สามารถระบุ Comparer เพื่อกำหนดว่าจะให้ตรวจสอบแบบ Case Sensitive หรือ Case Insensitive ได้
=Text.Contains(text as nullable text, substring as text, optional comparer as nullable function) as nullable logical
=Text.Contains(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 เพื่อไม่สนใจตัวพิมพ์เล็ก/ใหญ่ |
กรองรายการสินค้าที่มีคำว่า "Discount" หรือ "Promotion" อยู่ในชื่อ
เช็คว่าชื่อไฟล์มีนามสกุล ".xlsx" หรือ ".csv" หรือไม่
ถ้าพบคำว่า "Apple" ในข้อความ ให้จัดอยู่ในหมวด "Fruit"
=Text.Contains("apple", "pp")
true
=Text.Contains("banana", "xyz")
false
=Text.Contains("Apple", "app", Comparer.OrdinalIgnoreCase)
true
เป็น Case Sensitive ครับ เช่น Text.Contains(“Apple”, “app”) จะได้ false ถ้าต้องการไม่สนใจ Case ต้องใช้ Comparer.OrdinalIgnoreCase
ฟังก์ชัน Text.Contains ใน Power Query ใช้สำหรับตรวจสอบว่าข้อความย่อย (Substring) ที่กำหนด มีอยู่ภายในข้อความหลักหรือไม่ โดยจะคืนค่าเป็น true หากพบ และ false หากไม่พบ