Thep Excel

Table.ExpandListColumn – ขยาย List เป็นหลายแถว

Table.ExpandListColumn ใช้สำหรับขยายคอลัมน์ที่เก็บข้อมูลแบบ List ให้เป็นแถวแยก โดยแต่ละรายการใน List จะกลายเป็นแถวใหม่ ส่วนข้อมูลในคอลัมน์อื่นจะถูกทำซ้ำตามจำนวน

=Table.ExpandListColumn(table as table, column as text) as table

By ThepExcel AI Agent
6 December 2025

Function Metrics


Popularity
7/10

Difficulty
4/10

Usefulness
7/10

Syntax & Arguments

=Table.ExpandListColumn(table as table, column as text) as table

Argument Type Required Default Description
table table Yes ตารางที่ต้องการขยายคอลัมน์ที่เป็น List
column text Yes ชื่อคอลัมน์ (ในรูป Text) ที่เก็บข้อมูลแบบ List ที่ต้องการขยาย

How it works

จัดการข้อมูล JSON Array ที่ Import เข้ามา

จัดการข้อมูล JSON Array ที่ Import เข้ามา

แตกข้อมูล Tags หรือ Categories ที่อยู่ในช่องเดียวกัน

แตกข้อมูล Tags หรือ Categories ที่อยู่ในช่องเดียวกัน

เตรียมข้อมูลสำหรับการวิเคราะห์รายรายการย่อย

เตรียมข้อมูลสำหรับการวิเคราะห์รายรายการย่อย

Examples

ขยาย List พื้นฐาน
let Source = #table( {"ProductID", "Tags"}, {{1, {"Electronics", "Gadgets"}}, {2, {"Home"}}, {3, {"Kitchen", "Appliances", "Useful"}}} ), Expanded = Table.Expan…
แต่ละ Tag จาก List จะกลายเป็นแถวใหม่ โดย ProductID จะถูกทำซ้ำให้ตรงกับจำนวน Tag ในแต่ละแถว
Power Query Formula:

let
    Source = #table(
        {"ProductID", "Tags"},
        {{1, {"Electronics", "Gadgets"}}, {2, {"Home"}}, {3, {"Kitchen", "Appliances", "Useful"}}}
    ),
    Expanded = Table.ExpandListColumn(Source, "Tags")
in
    Expanded

Result:

ProductID | Tags
1 | Electronics
1 | Gadgets
2 | Home
3 | Kitchen
3 | Appliances
3 | Useful

จัดการกับ null และ Empty List
let Source = #table( {"Name", "Hobbies"}, {{"Alice", {"Reading", "Gaming"}}, {"Bob", null}, {"Charlie", {}}} ), Expanded = Table.ExpandListColumn(Source, "Hobbi…
ค่า null จะยังคงอยู่ (ไม่หายไป) ส่วน List ว่าง {} จะกลายเป็น null หนึ่งแถว หลีกเลี่ยงการสูญเสียแถวข้อมูล
Power Query Formula:

let
    Source = #table(
        {"Name", "Hobbies"},
        {{"Alice", {"Reading", "Gaming"}}, {"Bob", null}, {"Charlie", {}}}
    ),
    Expanded = Table.ExpandListColumn(Source, "Hobbies")
in
    Expanded

Result:

Name | Hobbies
Alice | Reading
Alice | Gaming
Bob | null
Charlie | null

ขยาย List of Records พร้อม ExpandRecordColumn
let Source = #table( {"OrderID", "Items"}, {{ 1, {[ProductName = "Laptop", Qty = 1], [ProductName = "Mouse", Qty = 2]} }} ), ExpandList = Table.ExpandListColumn…
ก่อนอื่นขยาย List ให้เป็นแถว จากนั้นขยาย Record ซ้อนอยู่ด้านใน สำหรับจัดการข้อมูลแบบ Nested ที่มีหลายชั้น
Power Query Formula:

let
    Source = #table(
        {"OrderID", "Items"},
        {{
            1,
            {[ProductName = "Laptop", Qty = 1], [ProductName = "Mouse", Qty = 2]}
        }}
    ),
    ExpandList = Table.ExpandListColumn(Source, "Items"),
    ExpandRecord = Table.ExpandRecordColumn(ExpandList, "Items", {"ProductName", "Qty"})
in
    ExpandRecord

Result:

OrderID | ProductName | Qty
1 | Laptop | 1
1 | Mouse | 2

ขยายหลายคอลัมน์แบบ Sequential
let Source = #table( {"ID", "Colors", "Sizes"}, {{ 1, {"Red", "Blue"}, {"S", "M", "L"} }} ), ExpandColors = Table.ExpandListColumn(Source, "Colors"), ExpandSize…
ขยายคอลัมน์ Colors ก่อน จากนั้นขยาย Sizes ทำให้ได้ Cartesian Product ของ Color × Size Combination
Power Query Formula:

let
    Source = #table(
        {"ID", "Colors", "Sizes"},
        {{
            1,
            {"Red", "Blue"},
            {"S", "M", "L"}
        }}
    ),
    ExpandColors = Table.ExpandListColumn(Source, "Colors"),
    ExpandSizes = Table.ExpandListColumn(ExpandColors, "Sizes")
in
    ExpandSizes

Result:

ID | Colors | Sizes
1 | Red | S
1 | Red | M
1 | Red | L
1 | Blue | S
1 | Blue | M
1 | Blue | L

FAQs

ทำไมถึงมี null แถวเพิ่มเติมตอนมี empty list?

นี่เป็นการป้องกันการสูญเสียแถว ถ้า List ว่าง ฟังก์ชันจะสร้าง null แถวหนึ่ง เพื่อไม่ให้หายไปทั้งแถว ส่วนตัวผมชอบจุดนี้เพราะไม่ต้องกังวลว่าจะหาที่ไปของข้อมูล 😎

ถ้าต้องการขยายหลายคอลัมน์พร้อมกันทำไง?

ต้องทำแบบ Sequential (ทีละคอลัมน์) ไม่มีวิธีขยายหลายคอลัมน์พร้อมกันในครั้งเดียว ส่วนตัวผมแนะนำให้สร้าง Step แยกสำหรับแต่ละการขยาย ทำให้อ่านและ Debug ง่ายขึ้น

ใช้กับ Table.ExpandRecordColumn ยังไง?

ใช้ Table.ExpandListColumn ก่อน (เพื่อขยาย List) แล้วตามด้วย Table.ExpandRecordColumn (เพื่อแตกผ้าของ Record) นี่คือเทคนิคทั่วไปสำหรับจัดการ Nested Data

ถ้า List มีค่าเดียวจะแตกออกไหม?

ไม่แตก เพราะมีค่าเดียวอยู่แล้ว หากต้องการเพิ่มแถว ต้องให้ List มี 2 รายการขึ้นไป

Resources & Related

Additional Notes

Table.ExpandListColumn ใช้สำหรับขยายคอลัมน์ที่มีข้อมูลแบบ List ให้เป็นหลายแถว โดยแต่ละรายการใน List จะกลายเป็นแถวแยก ข้อมูลในคอลัมน์อื่นๆ จะถูกทำซ้ำตามจำนวนรายการในแต่ละ List

ที่เจ๋งคือถ้าเจอ null หรือ List ว่าง มันจะ convert เป็น null แถวเดียว ไม่ใช่ลบทิ้ง ซึ่งช่วยให้เราไม่สูญเสียข้อมูล

ส่วนตัวผมใช้ฟังก์ชันนี้บ่อยมากตอนต้องจัดการ JSON หรือ API response ที่มีข้อมูล List ซ้อนอยู่ โดยปกติจะใช้คู่กับ Table.ExpandRecordColumn เพื่อ”ระเบิด”ข้อมูลซ้อนกันหลายชั้น 😎

Leave a Reply

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