Thep Excel

Number.From – แปลงค่าเป็นตัวเลข

Number.From จะพยายามแปลงค่า Input ให้เป็น Number หากเป็น Text จะพยายาม Parse ตัวเลขออกมา หากเป็น Date/Time จะแปลงเป็น Serial Number (เช่นเดียวกับ Excel)

=Number.From(value as any, optional culture as nullable text) as nullable number

By ThepExcel AI Agent
3 December 2025

Function Metrics


Popularity
7/10

Difficulty
2/10

Usefulness
7/10

Syntax & Arguments

=Number.From(value as any, optional culture as nullable text) as nullable number

Argument Type Required Default Description
value any Yes ค่าที่ต้องการแปลงเป็นตัวเลข สามารถเป็น Text, Date, Time, Logical, Duration หรือ Number เดิม
culture text Optional null รหัสวัฒนธรรม (Culture Code) เช่น “en-US” หรือ “th-TH” มีผลต่อการแปลทศนิยมและหลักพัน (en-US ใช้ . คั่นทศนิยม และ , คั่นหลักพัน ส่วน de-DE ใช้สวนกลับ)

How it works

แปลงข้อความเป็นตัวเลข

แปลง "123.45" ให้เป็นตัวเลข 123.45 เพื่อนำไปคำนวณ

แปลงวันที่เป็น Serial Number

แปลงค่า Date ให้เป็นตัวเลข (เช่น 45658) เพื่อใช้ในการคำนวณทางคณิตศาสตร์

Examples

ตัวอย่างที่ 1: แปลงข้อความตัวเลข
Number.From("123.45")
แปลงข้อความ "123.45" เป็นตัวเลข 123.45
Power Query Formula:

= Number.From("123.45")

Result:

123.45

ตัวอย่างที่ 2: แปลงวันที่เป็น Serial Number
Number.From(#date(2020, 3, 20))
แปลงวันที่ 20 มีนาคม 2020 เป็น Serial Number แบบ Excel (วันที่ 1 ต่อเทศกาล)
Power Query Formula:

= Number.From(#date(2020, 3, 20))

Result:

43910

ตัวอย่างที่ 3: ใช้ Culture Parameter
Number.From("1.234,56", "de-DE")
แปลงข้อความรูปแบบเยอรมัน (ใช้ . คั่นพัน และ , คั่นทศนิยม) ให้เป็นตัวเลข 1234.56
Power Query Formula:

= Number.From("1.234,56", "de-DE")

Result:

1234.56

ตัวอย่างที่ 4: แปลง Logical Value
Number.From(true)
แปลง true เป็น 1 และ false เป็น 0
Power Query Formula:

= Number.From(true)

Result:

1

ตัวอย่างที่ 5: แปลงเวลาเป็น Fractional Day
Number.From(#time(12, 0, 0))
แปลงเวลา 12:00:00 เป็น 0.5 (ครึ่งวัน)
Power Query Formula:

= Number.From(#time(12, 0, 0))

Result:

0.5

ตัวอย่างที่ 6: ใช้กับ try-otherwise เพื่อจัดการ Error
let Source = Table.FromRows({{"100"}, {"abc"}, {"50.5"}}, {"Value"}), Converted = Table.AddColumn(Source, "NumValue", each try Number.From([Value]) otherwise nu…
ใช้ try-otherwise เพื่อแปลงข้อความเป็นตัวเลข ถ้าแปลงไม่ได้จะกลับเป็น null แทนที่จะ Error
Power Query Formula:

let
    Source = Table.FromRows({{"100"}, {"abc"}, {"50.5"}}, {"Value"}),
    Converted = Table.AddColumn(Source, "NumValue", each try Number.From([Value]) otherwise null)
in
    Converted

Result:

ตารางแสดง Value 100 และ 50.5 เป็น Number, abc เป็น null

FAQs

Number.From ต่างจาก Number.FromText อย่างไร?

Number.FromText ใช้ได้เฉพาะกับ Text เท่านั้น แต่ Number.From ใช้กับค่าประเภทอื่นได้ด้วย (เช่น Date, Time, Logical, Duration) ถ้าค่าเป็น Text แล้วต้องการตัวเลือกเฉพาะ Text จะใช้ Number.FromText ได้

ถ้าแปลงไม่ได้จะเกิดอะไร?

ปกติ Number.From จะ Return Error ถ้าข้อมูลไม่สามารถแปลงได้ ดังนั้นควรใช้ try-otherwise เพื่อจัดการ Error

Culture Parameter มีความสำคัญแค่ไหน?

สำคัญมาก หากข้อมูลใช้รูปแบบ Culture ที่ต่างจาก Default (en-US) ต้องระบุ Culture หรือจะแปลงค่าผิด เช่น “1.000,50” ในเยอรมัน คือ 1000.50 แต่ถ้าไม่ระบุ Culture อาจแปลงเป็น 1.00050

Date/Time แปลงเป็น Number ได้ยังไง?

Power Query ใช้ OLE Automation Date System คล้ายกับ Excel โดยนับจำนวนวันตั้งแต่ 1 มกราคม ค.ศ. 1900 สำหรับ Date และ Fractional Day สำหรับ Time

Resources & Related

Additional Notes

ฟังก์ชัน Number.From ใน Power Query ใช้สำหรับแปลงค่าต่างๆ ให้เป็นชนิดข้อมูลตัวเลข (Number) รองรับการแปลงจากข้อความ (Text), วันที่, เวลา หรือค่าอื่นๆ เหมือนกับการ Cast ชนิดข้อมูลในภาษาโปรแกรมมิ่ง

ที่เจ๋งของ Number.From คือมันรองรับการแปลงจากหลายประเภทข้อมูล ไม่ว่าจะเป็นข้อความ วันที่ เวลา หรือแม้แต่ Logical (true/false) ยังสามารถแปลงได้ ส่วนใหญ่ผมใช้ในการแปลง Text ตัวเลขที่มีทศนิยมหรือหลักพันที่อยู่ในรูปแบบต่างๆ เนื่องจาก Power Query บางครั้งไม่ได้อ่านข้อมูลตัวเลขออกมาเป็น Type Number โดยอัตโนมัติ

ส่วนตัวผมแนะนำให้ใช้ Number.From คู่กับ try-otherwise เพื่อหลีกเลี่ยง Error เมื่อข้อมูลไม่สามารถแปลงได้ 😎

Leave a Reply

Your email address will not be published. Required fields are marked *