Thep Excel

Table.TransformRowsแปลงแต่ละแถวของตารางเป็นรายการ

Table.TransformRows ใช้สำหรับประมวลผลแต่ละแถวของตารางด้วยฟังก์ชนที่กำหนด แล้วคืนผลลัพธ์กลับมาเป็น List (ไม่ใช่ Table)

fx
=Table.TransformRows(table, transform) as list

ความนิยม5/10
ความยาก6/10
ประโยชน์6/10

อัปเดต 6 December 2025

Syntax & Arguments

อาร์กิวเมนต์ ชนิด คำอธิบาย
table table ตารางที่ต้องการประมวลผลแต่ละแถว
transform function ฟังก์ชันที่ใช้แปลงข้อมูลแต่ละแถว สามารถใช้ each [Column] หรือ (row) => expression ได้

Additional Notes

Table.TransformRows(table as table, transform as function) as list ใช้สำหรับแปลง Table เป็น List โดยประมวลผลแต่ละแถว

ที่เจ๋งของ Table.TransformRows คือมันสามารถดึงแค่คอลัมน์เดียว บวกค่าหลายคอลัมน์ หรือแปลงแต่ละแถวเป็น Record ใหม่อย่างสมบูรณ์ได้ ทีแรกฉันงง ว่าทำไมต้องแปลงเป็น List แทนที่จะใช้ Table.AddColumn ก็ได้ แต่พอเข้าใจแล้ว มันมีประโยชน์มากเวลา Export ข้อมูลไป API หรือเก็บเป็น JSON list แทนที่จะเป็นตารางครับ

ส่วนตัวผม Table.TransformRows มักใช้คู่กับ List.ToTable() เมื่อต้องการแปลง List of Records กลับเป็น Table เพื่อสร้างตารางชุดใหม่ที่มีโครงสร้างต่างจากตัวเดิม

How it works

สร้าง List ใหม่จากการคำนวณค่าในแต่ละแถว

สร้าง List ใหม่จากการคำนวณค่าในแต่ละแถว

แปลงโครงสร้างข้อมูลจากตารางเป็น List ของ Record หรือค่าอื่นๆ

แปลงโครงสร้างข้อมูลจากตารางเป็น List ของ Record หรือค่าอื่นๆ

เตรียมข้อมูลสำหรับการประมวลผลด้วย List functions

เตรียมข้อมูลสำหรับการประมวลผลด้วย List functions

Examples

ดึงค่าจากคอลัมน์เดียวเป็น Listlet Sales = Table.FromRecords({ [OrderID = 1, Amount = 1500], [OrderID = 2, Amount = 2300], [OrderID = 3, Amount = 800] }), AmountList = Table.TransformRows(Sal…

ใช้ each [Amount] เพื่อดึงค่าจากคอลัมน์ Amount จากแต่ละแถว ผลลัพธ์คือ List ของตัวเลข

fx
let
Sales = Table.FromRecords({
[OrderID = 1, Amount = 1500],
[OrderID = 2, Amount = 2300],
[OrderID = 3, Amount = 800]
}),
AmountList = Table.TransformRows(Sales, each [Amount])
in
AmountList
// Result: {1500, 2300, 800}

ผลลัพธ์{1500, 2300, 800}
คำนวณค่าจากหลายคอลัมน์let Invoice = Table.FromRecords({ [Qty = 5, Price = 100], [Qty = 3, Price = 200], [Qty = 10, Price = 50] }), Totals = Table.TransformRows(Invoice, each [Qty] *…

สำหรับแต่ละแถว คำนวณ Qty * Price แล้วเก็บผลลัพธ์ไว้ใน List

fx
let
Invoice = Table.FromRecords({
[Qty = 5, Price = 100],
[Qty = 3, Price = 200],
[Qty = 10, Price = 50]
}),
Totals = Table.TransformRows(Invoice, each [Qty] * [Price])
in
Totals
// Result: {500, 600, 500}

ผลลัพธ์{500, 600, 500}
แปลงแต่ละแถวเป็น Record ใหม่ที่มีคอลัมน์เพิ่มเติมlet Employee = Table.FromRecords({ [ID = 1, Name = "Alice", Salary = 50000], [ID = 2, Name = "Bob", Salary = 55000] }), WithBonus = Table.TransformRows( Employe…

ใช้ (row) => […] เพื่อสร้าง Record ใหม่สำหรับแต่ละแถว มีการคำนวณเงินเดือนประจำปี และโบนัส

fx
let
Employee = Table.FromRecords({
[ID = 1, Name = "Alice", Salary = 50000],
[ID = 2, Name = "Bob", Salary = 55000]
}),
WithBonus = Table.TransformRows(
Employee,
(row) => [
ID = row[ID],
Name = row[Name],
Annual = row[Salary] * 12,
Bonus = Number.ToText(row[Salary] * 0.1)
]
)
in
WithBonus
// Result: {[ID = 1, Name = "Alice", Annual = 600000, Bonus = "5000"], [ID = 2, Name = "Bob", Annual = 660000, Bonus = "5500"]}

ผลลัพธ์{[ID = 1, Name = "Alice", Annual = 600000, Bonus = "5000"], [ID = 2, Name = "Bob", Annual = 660000, Bonus = "5500"]}
แปลงเป็น Text List พร้อมการฟอร์แมตlet Products = Table.FromRecords({ [ProductName = "Laptop", Category = "Electronics"], [ProductName = "Mouse", Category = "Electronics"], [ProductName = "Desk",…

รวมค่าจากหลายคอลัมน์และฟอร์แมตเป็นข้อความเดียว

fx
let
Products = Table.FromRecords({
[ProductName = "Laptop", Category = "Electronics"],
[ProductName = "Mouse", Category = "Electronics"],
[ProductName = "Desk", Category = "Furniture"]
}),
Labels = Table.TransformRows(
Products,
each [Category] & ": " & [ProductName]
)
in
Labels
// Result: {"Electronics: Laptop", "Electronics: Mouse", "Furniture: Desk"}

ผลลัพธ์{\"Electronics: Laptop\", \"Electronics: Mouse\", \"Furniture: Desk\"}

FAQs

Table.TransformRows กับ Table.AddColumn ต่างกันตรงไหน?+

Table.AddColumn สร้างคอลัมน์ใหม่แล้วคืน Table กลับมา ส่วน Table.TransformRows แปลงแต่ละแถวแล้วคืน List ไม่ใช่ Table ใช้ Table.TransformRows ตอนต้อง Export ข้อมูล API หรือประมวลผลแบบแถวต่อแถว

Table.TransformRows กับ List.Transform ต่างกันตรงไหน?+

Table.TransformRows ทำงานกับ Table ได้ใช้ [ColumnName] โดยตรง ส่วน List.Transform ทำงานกับ List และ (item) => expression List.Transform เหมาะสำหรับข้อมูลที่เป็น List อยู่แล้ว ส่วน Table.TransformRows เหมาะสำหรับ Table

Transform function ต้องคืน Type เดียวกันหรือ?+

ไม่จำเป็น Transform function สามารถคืน type ต่างๆ ได้ (text, number, record, list) ตัวอย่างเช่น each [Amount] คืน number ส่วน each [Name] & ":" & [ID] คืน text ได้

ถ้าตารางมี 100,000 แถว ดำเนินการช้าไหม?+

ความเร็วขึ้นอยู่กับความซับซ้อนของฟังก์ชัน transform ถ้าเรียบง่าย (แค่ [Column] หรือบวกลบ) ไม่ช้า แต่ถ้า transform มี lookup หรือเรียก API ในแต่ละแถว จะช้ามากๆ ลอง Table.AddColumn เพราะบาง transform สามารถใช้ได้ทั้งสองฟังก์ชัน

Resources & Related

Comments

อีเมลของคุณจะไม่ถูกเผยแพร่