Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Expand Columns for Table with Unknown Column Names

I seached Google for "power query expand all columns".

Top search result is from 2014 and seemed really complex, second item found did not seem simpler and only 3rd result was from this forum, by @ImkeF from 2018. (note-to-self, 1st stop to seek answers should be this forum) 

 

In short, the trick is to get the list of column names (Table.ColumnNames), on the column which holds the table of unknown column names (using Table.Combine).

 

It you have a Table (say it is called TABLE_OF_TABLES) and it has a column that each value is a Table with unknown columns names (say column is names table_column), you can expand it using:

Table.ExpandTableColumn(
                TABLE_OF_TABLES,
                "table_column",
                Table.ColumnNames(Table.Combine(TABLE_OF_TABLES[table_column])),
                Table.ColumnNames(Table.Combine(TABLE_OF_TABLES[table_column]))
                )

Since it took me some time to get is right and since this looks like a pretty common task I am posting the functions I implemented. Hope others will benefit from it.

 

Function GetSheetDataFromFiles

= (sheetName) =>
let
    fileNames = FILE_NAMES, // A table with a single column called "Data Source File Name", each entry is a file name (full path)
    readFileData = Table.AddColumn(fileNames,
                "fileData",
                each GetSheetData([Data Source File Name], sheetName)
    ),
    expandFileData = Table.ExpandTableColumn(
                readFileData,
                "fileData",
                Table.ColumnNames(Table.Combine(readFileData[fileData])),
                Table.ColumnNames(Table.Combine(readFileData[fileData]))
    ),
    removeFileName = Table.RemoveColumns(expandFileData,{"Data Source File Name"})
in
    removeFileName

Function GetSheetData

= (fileName, sheetName) =>
let
    Source = Excel.Workbook(File.Contents(fileName), null, true),
    allData = Source{[Item=sheetName,Kind="Sheet"]}[Data],
    promotedHeaders = Table.PromoteHeaders(allData, [PromoteAllScalars=true])
in
    promotedHeaders

 

3 REPLIES 3
JoeYo
Advocate I
Advocate I

Amazing, thankyou!

Aidan43
New Member

The equivalent for expanding records within records (see screenshot) is the following:

 

Aidan43_1-1740144537456.png

 

= Table.ExpandRecordColumn(
#"Expanded output_data",
"output_data",
Record.FieldNames(
Record.Combine(
#"Expanded output_data"[output_data]
)
),
Record.FieldNames(
Record.Combine(
#"Expanded output_data"[output_data]
)
)
)

 

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Thank you for your sharing! 

 

 

 

Best Regards,

Icey

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.