Table.Combine ใช้สำหรับรวม list ของ table เข้าเป็น table เดียว ยับยั้ง append ตัว 1 แถวหลาย ๆ ตารางพร้อมกัน
=Table.Combine(tables as list, optional columns as any) as table
=Table.Combine(tables as list, optional columns as any) as table
| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| tables | list | Yes | List ของ tables ที่ต้องการรวมกัน เช่น {Table1, Table2, Table3} | |
| columns | any | Optional | null | Optional – ระบุ column structure ของ result table หรือใช้ union ของทุก column จาก input tables |
let Table1 = Table.FromRecords({ [CustomerID = 1, Name = "Bob", Phone = "123-4567"], [CustomerID = 2, Name = "Jim", Phone = "987-6543"] }), Table2 = Table.FromR…= let
Table1 = Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567"],
[CustomerID = 2, Name = "Jim", Phone = "987-6543"]
}),
Table2 = Table.FromRecords({
[CustomerID = 3, Name = "Paul", Phone = "543-7890"]
}),
Table3 = Table.FromRecords({
[CustomerID = 4, Name = "Alice", Phone = "246-1357"]
}),
Combined = Table.Combine({Table1, Table2, Table3})
in
Combined
Table with 4 rows:
[CustomerID = 1, Name = "Bob", Phone = "123-4567"]
[CustomerID = 2, Name = "Jim", Phone = "987-6543"]
[CustomerID = 3, Name = "Paul", Phone = "543-7890"]
[CustomerID = 4, Name = "Alice", Phone = "246-1357"]
let ContactsEmail = Table.FromRecords({ [Name = "Bob", Email = "bob@company.com"], [Name = "Jim", Email = "jim@company.com"] }), ContactsPhone = Table.FromRecor…= let
ContactsEmail = Table.FromRecords({
[Name = "Bob", Email = "bob@company.com"],
[Name = "Jim", Email = "jim@company.com"]
}),
ContactsPhone = Table.FromRecords({
[Name = "Paul", Phone = "543-7890"],
[Name = "Alice", Phone = "246-1357"]
}),
AllContacts = Table.FromRecords({
[Name = "Charlie", Email = "charlie@company.com", Phone = "135-7924"]
}),
Combined = Table.Combine({ContactsEmail, ContactsPhone, AllContacts})
in
Combined
Table with 5 rows and 3 columns (Name, Email, Phone):
[Name = "Bob", Email = "bob@company.com", Phone = null]
[Name = "Jim", Email = "jim@company.com", Phone = null]
[Name = "Paul", Email = null, Phone = "543-7890"]
[Name = "Alice", Email = null, Phone = "246-1357"]
[Name = "Charlie", Email = "charlie@company.com", Phone = "135-7924"]
let Sales2024 = Table.FromRecords({ [Region = "North", Amount = 1000, Year = 2024], [Region = "South", Amount = 1500, Year = 2024] }), Sales2025 = Table.FromRec…= let
Sales2024 = Table.FromRecords({
[Region = "North", Amount = 1000, Year = 2024],
[Region = "South", Amount = 1500, Year = 2024]
}),
Sales2025 = Table.FromRecords({
[Region = "East", Amount = 2000, Year = 2025],
[Region = "West", Amount = 1800, Year = 2025]
}),
AllSales = Table.Combine(
{Sales2024, Sales2025},
{"Region", "Amount", "Year"}
)
in
AllSales
Table with 4 rows:
[Region = "North", Amount = 1000, Year = 2024]
[Region = "South", Amount = 1500, Year = 2024]
[Region = "East", Amount = 2000, Year = 2025]
[Region = "West", Amount = 1800, Year = 2025]
let NorthRegionData = Table.FromRecords({ [Store = "A", Sales = 5000, Staff = 10], [Store = "B", Sales = 7000, Staff = 15] }), SouthRegionData = Table.FromRecor…= let
NorthRegionData = Table.FromRecords({
[Store = "A", Sales = 5000, Staff = 10],
[Store = "B", Sales = 7000, Staff = 15]
}),
SouthRegionData = Table.FromRecords({
[Store = "C", Sales = 4500, Staff = 8],
[Store = "D", Sales = 6000, Staff = 12]
}),
EastRegionData = Table.FromRecords({
[Store = "E", Sales = 5500, Staff = 11]
}),
AllStores = Table.Combine({NorthRegionData, SouthRegionData, EastRegionData}),
WithRegion = Table.AddColumn(
AllStores,
"Region",
each if [Store] = "A" or [Store] = "B" then "North"
else if [Store] = "C" or [Store] = "D" then "South"
else "East"
)
in
WithRegion
Table with 5 rows and 4 columns (Store, Sales, Staff, Region):
[Store = "A", Sales = 5000, Staff = 10, Region = "North"]
[Store = "B", Sales = 7000, Staff = 15, Region = "North"]
[Store = "C", Sales = 4500, Staff = 8, Region = "South"]
[Store = "D", Sales = 6000, Staff = 12, Region = "South"]
[Store = "E", Sales = 5500, Staff = 11, Region = "East"]
let Q1Sales = Table.FromRecords({ [Month = "Jan", Amount = 1200], [Month = "Feb", Amount = 1500], [Month = "Mar", Amount = 1800] }), Q2Sales = Table.FromRecords…= let
Q1Sales = Table.FromRecords({
[Month = "Jan", Amount = 1200],
[Month = "Feb", Amount = 1500],
[Month = "Mar", Amount = 1800]
}),
Q2Sales = Table.FromRecords({
[Month = "Apr", Amount = 2000],
[Month = "May", Amount = 1900],
[Month = "Jun", Amount = 2200]
}),
AllSales = Table.Combine({Q1Sales, Q2Sales}),
LargeSales = Table.SelectRows(AllSales, each [Amount] >= 1800)
in
LargeSales
Table with 4 rows:
[Month = "Mar", Amount = 1800]
[Month = "Apr", Amount = 2000]
[Month = "May", Amount = 1900]
[Month = "Jun", Amount = 2200]
Table.Append รวม 2 tables เพียงอย่างเดียว ส่วน Table.Combine รวม list ของ tables ได้ กดหลาย ๆ ตัวพร้อมกัน ถ้ามี tables มาก ๆ Table.Combine จะเขียนสั้นกว่า
มันจะทำ union ของ columns ทั้งหมด และเติม null ลงไปให้ column ที่ขาด ตัวอย่าง Table A มี [Name, Email] แต่ Table B มี [Name, Phone] ผลลัพธ์จะมี [Name, Email, Phone] โดย Email ใน rows จาก B จะเป็น null
ส่ง list ของ column names ในพารามิเตอร์ที่สอง เช่น Table.Combine({T1, T2}, {“Name”, “Amount”}) มันจะเลือกแค่ 2 columns นี้
ถ้า list ว่าง {} จะได้ error ถ้า table บางตัวว่าง มันก็จะรวมแต่ตัวที่มีข้อมูล ผลลัพธ์อาจเป็น empty table หรือมีแถวได้
ได้ แต่ต้องใช้ List ของ tables เช่น Table.Combine(List.Generate(…)) หรือ append query references ลงใน list ก่อน
Table.Combine รวม list ของ table เข้าเป็น table เดียว โดยแล้ว schema จากทุก table เข้าด้วยกัน ถ้ามี column ที่อยู่ใน table บางตัวแต่ไม่อยู่ในตัวอื่น จะเติม null ลงไปอัตโนมัติ
ที่เจ๋งคือมันทำให้เวลาต้อง append table หลาย ตัว ไม่ต้องเขียน Table.ExpandRecords สองครั้ง หรือ chain query ยาว ๆ ได้
ส่วนตัวผม มักใช้ Table.Combine เวลาต้องรวมข้อมูลจากหลาย worksheet หรือหลาย API endpoint ที่ structure มันต่างกัน ทำให้ combine ได้ง่ายขึ้นเยอะครับ 😎