Table.FromList Function in Power Query
The Table.FromList function in Power Query converts a list into a table by applying the specified splitting function to each item in the list.
Syntax
Table.FromList( list as list, optional splitter as nullable function, optional columns as any, optional default as any, optional extraValues as nullable number ) as table
The function has the following parameters:
- list: The list to convert into a table.
- splitter: Optional function to split each item into multiple columns (e.g., Splitter.SplitTextByDelimiter). Default is Splitter.SplitByNothing().
- columns: Optional list of column names.
- default: Optional default value to use if splitting results in missing values.
- extraValues: Optional number specifying how to handle extra values when splitting.
Example: Simple List to Table.
Power Query M
let MyList = {1, 2, 3, 4}, ResultTable = Table.FromList(MyList, Splitter.SplitByNothing(), {"Number"}) in ResultTable
The output of the above code is shown below:
Number
1
2
3
4
Example: Split Text Items into Multiple Columns.
Power Query M
let MyList = {"Alice,10", "Bob,15", "Charlie,20"}, ResultTable = Table.FromList( MyList, Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Name", "Score"} ) in ResultTable
The output of the above code is shown below:
Name Score
Alice 10
Bob 15
Charlie 20
Example: Using Default Value for Missing Split Items.
Power Query M
let MyList = {"Alice,10", "Bob"}, ResultTable = Table.FromList( MyList, Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Name", "Score"}, "N/A" ) in ResultTable
The output of the above code is shown below:
Name Score
Alice 10
Bob N/A