ตัวอย่างที่ 1: ตรวจสอบความยาวของ Binary ง่ายๆ
=Binary.Length(Binary.FromList({0, 1, 2, 3, 4}))
5
ตรวจสอบจำนวน Bytes ในค่า Binary
Binary.Length ตรวจสอบและคืนค่าจำนวน Bytes ในค่า Binary เป็นตัวเลข เช่น Binary ที่มี 5 Bytes จะคืนค่า 5
=Binary.Length(binary as nullable binary) as nullable number
=Binary.Length(binary as nullable binary) as nullable number
| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| binary | binary | Yes | ค่า Binary (nullable) ที่ต้องการตรวจสอบความยาว (จำนวน Bytes) |
ใช้ Binary.Length เพื่อตรวจสอบว่า Binary มีขนาดเป็นจำนวน Bytes เท่าไร ประโยชน์สำหรับตรวจสอบว่าไฟล์สมบูรณ์
เช่น หากคาดว่า Binary ควรมีความยาว 256 Bytes แต่จริงๆได้ 255 Bytes แสดงว่าข้อมูลบกพร่อง
ใช้ Binary.Length ตัดสินใจว่าจะแบ่งหรือประมวลผล Binary ด้วยวิธีไหน
=Binary.Length(Binary.FromList({0, 1, 2, 3, 4}))
5
let
Text = "Hello World",
BinaryData = Binary.FromText(Text),
Length = Binary.Length(BinaryData)
in
Length
11
let
EmptyBinary = Binary.FromList({}),
LengthEmpty = Binary.Length(EmptyBinary),
Part1 = Binary.FromList({65, 66}),
Part2 = Binary.FromList({67, 68}),
Combined = Binary.Combine({Part1, Part2}),
LengthCombined = Binary.Length(Combined)
in
[EmptyLength = LengthEmpty, CombinedLength = LengthCombined]
[EmptyLength = 0, CombinedLength = 4]
Binary.Length ตรวจสอบจำนวน Bytes ในข้อมูล Binary ส่วน Text.Length ตรวจสอบจำนวนตัวอักษรในข้อความ สำหรับข้อความภาษาอังกฤษ 1 ตัวอักษร = 1 Byte แต่ภาษาอื่นอาจต่างกัน
Binary.Length(null) จะคืนค่า null ตามหลักการ null propagation ของ Power Query
ไม่มีขีดจำกัดในเรื่องความยาว Binary แต่ขึ้นอยู่กับหน่วยความจำที่มีอยู่ใน Power Query
ได้บางส่วน เช่น ตรวจสอบว่า Binary มีความยาวตามลักษณะเฉพาะของไฟล์ (Image header ควรมีความยาวเท่ากัน) แต่การตรวจสอบรูปแบบต้องตรวจสอบเนื้อหา (Signature bytes) ไม่ใช่แค่ความยาว
ฟังก์ชัน Binary.Length ใน Power Query ใช้สำหรับตรวจสอบจำนวน Bytes ในค่า Binary ผลลัพธ์คือตัวเลขที่แสดงความยาวของ Binary นับจาก Bytes ตัวแรกถึงตัวสุดท้าย เหมาะสำหรับการตรวจสอบขนาดข้อมูลหรือตรวจสอบข้อมูล Binary