Table.FillDown เติมเต็มค่า null ด้วยค่าจากแถวด้านบน (forward fill) เหมาะสำหรับข้อมูลที่มีการ merge cell หรือจัดกลุ่มข้อมูลแบบ hierarchical ทำให้ได้ตารางที่สมบูรณ์พร้อมใช้ต่อได้เลย
= Table.FillDown(table as table, columns as list) as table
= Table.FillDown(table as table, columns as list) as table
| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| table | table | Yes | ตารางข้อมูลต้นฉบับที่มีค่า null ที่ต้องการเติมเต็ม | |
| columns | list | Yes | List ของชื่อคอลัมน์ที่ต้องการ fill down (เช่น {“Department”, “Category”}) |
let Source = #table( {"Category", "Item", "Price"}, {{"Fruit", "Apple", 10}, {null, "Banana", 5}, {null, "Orange", 8}, {"Veg", "Carrot", 3}, {null, "Corn", 4}}…= let
Source = #table(
{"Category", "Item", "Price"},
{{"Fruit", "Apple", 10}, {null, "Banana", 5}, {null, "Orange", 8}, {"Veg", "Carrot", 3}, {null, "Corn", 4}}
),
Filled = Table.FillDown(Source, {"Category"})
in
Filled
Table: (Fruit, Apple, 10), (Fruit, Banana, 5), (Fruit, Orange, 8), (Veg, Carrot, 3), (Veg, Corn, 4)
let Source = #table( {"Company", "Department", "Employee", "Salary"}, {{"TechCorp", "IT", "Alice", 50000}, {null, null, "Bob", 48000}, {null, "HR", "Carol", 450…= let
Source = #table(
{"Company", "Department", "Employee", "Salary"},
{{"TechCorp", "IT", "Alice", 50000}, {null, null, "Bob", 48000}, {null, "HR", "Carol", 45000}, {null, null, "Dave", 46000}, {"FineCorp", "Finance", "Eve", 55000}}
),
Filled = Table.FillDown(Source, {"Company", "Department"})
in
Filled
Table: (TechCorp, IT, Alice, 50000), (TechCorp, IT, Bob, 48000), (TechCorp, HR, Carol, 45000), (TechCorp, HR, Dave, 46000), (FineCorp, Finance, Eve, 55000)
let Source = #table( {"Section", "Subsection", "Item", "Qty"}, {{"OfficeSupplies", "Writing", "Pen", 100}, {null, null, "Pencil", 50}, {null, "Paper", "A4", 200…= let
Source = #table(
{"Section", "Subsection", "Item", "Qty"},
{{"OfficeSupplies", "Writing", "Pen", 100}, {null, null, "Pencil", 50}, {null, "Paper", "A4", 200}, {null, null, "Notebook", 30}}
),
Filled = Table.FillDown(Source, {"Section", "Subsection"})
in
Filled
Table: (OfficeSupplies, Writing, Pen, 100), (OfficeSupplies, Writing, Pencil, 50), (OfficeSupplies, Paper, A4, 200), (OfficeSupplies, Paper, Notebook, 30)
let Source = #table( {"Date", "Region", "Product", "Sales"}, {{"2025-01-01", "Bangkok", "Laptop", 5}, {null, null, "Desktop", 3}, {null, null, "Monitor", 2}, {"…= let
Source = #table(
{"Date", "Region", "Product", "Sales"},
{{"2025-01-01", "Bangkok", "Laptop", 5}, {null, null, "Desktop", 3}, {null, null, "Monitor", 2}, {"2025-01-02", "Chiang Mai", "Laptop", 4}, {null, null, "Phone", 6}}
),
Filled = Table.FillDown(Source, {"Date", "Region"})
in
Filled
Table: (2025-01-01, Bangkok, Laptop, 5), (2025-01-01, Bangkok, Desktop, 3), (2025-01-01, Bangkok, Monitor, 2), (2025-01-02, Chiang Mai, Laptop, 4), (2025-01-02, Chiang Mai, Phone, 6)
let Source = Csv.Document(File.Contents("C:\\data.csv"), null, ",", null, 1252), Headers = Table.PromoteHeaders(Source), Filled = Table.FillDown(Headers, {"Cate…= let
Source = Csv.Document(File.Contents("C:\\data.csv"), null, ",", null, 1252),
Headers = Table.PromoteHeaders(Source),
Filled = Table.FillDown(Headers, {"Category", "SubCategory"}),
Filtered = Table.SelectRows(Filled, each [Sales] > 1000)
in
Filtered
Table: ข้อมูล sales > 1000 พร้อมข้อมูล Category และ SubCategory สมบูรณ์แล้ว
ค่า null ในแถวแรก (ที่ไม่มีค่าด้านบนให้ยืมมา) จะยังคงเป็น null นะครับ เพราะว่า FillDown จะดึงค่าจากแถวด้านบนเท่านั้น ถ้าแถวแรกมี null ไม่มีค่าด้านบนจึงไม่สามารถเติมได้ – ลองใช้ Table.ReplaceValue หรือ Table.FillUp สำหรับแถวแรก
เจอบ่อยครับ 😅 ส่วนมากเพราะว่าไม่มี null เลย ถ้าคอลัมน์ไม่มี null อยู่แล้ว FillDown ก็ไม่ต้องทำอะไร ลองเช็คด้วย View ที่ทำให้เห็น null หรือใช้ Table.Profile เพื่อดูจำนวน null ในแต่ละคอลัมน์
FillDown ดึงค่าจากแถวด้านบน (forward fill), FillUp ดึงค่าจากแถวด้านล่าง (backward fill) – เลือกให้เหมาะกับลักษณะข้อมูลของเราครับ
ชื่อคอลัมน์ในลิสต์ต้องตรงกับชื่อในตาราง (case-sensitive) – เช็คสะกดให้ถูกนะครับ ถ้าคอลัมน์ไม่มี FillDown จะ error ทันที
ได้ครับ เช่น เก็บชื่อคอลัมน์ในตัวแปรแล้วส่งเข้า FillDown ได้เลย – เรียก List.Select หรือ Table.ColumnNames เพื่อหาคอลัมน์ที่ต้องการเติม
Table.FillDown(table, columns) ใช้เติมเต็มค่าว่าง (null) ในคอลัมน์ที่ระบุ ด้วยค่าจากแถวข้างบนสุด (forward fill)
ที่เจ๋งคือ ฟังก์ชันนี้ช่วยแก้ปัญหาข้อมูลที่มาจาก Excel ที่เคยมี merge cell – แค่ใส่ชื่อแผนก/หัวข้อไว้บรรทัดแรก แล้วทำให้ null ลงมา ปล่อยให้ FillDown ช่วยเติมให้ครับ ทำให้การ transform ข้อมูลเร็วขึ้นเยอะ 😎
ส่วนตัวผมใช้ Table.FillDown ก่อน Table.SelectRows เสมอ เพราะฉะนั้นข้อมูลจึงเสร็จสมบูรณ์แล้วจึงกรองข้อมูลต่อ