Professional Documents
Culture Documents
Working With Tables in Power Query M in Power BI
Working With Tables in Power Query M in Power BI
Working With Tables in Power Query M in Power BI
> Tables
Working With Tables in
Creation Table.InsertRows(
Musicians,
#table(
{[FirstName = "Bad", LastName = "Bunny", BirthDate = #date(1994, 3, 10)]}
}
Table.Combine(
Musicians,
Learn Power BI online at www.DataCamp.com // Create a table from a list of records with FromRecords()
Table.FromRecords({
Table.FromRecords({
[
})
BirthYear = 1759,
IsDataScientist = true,
>
ChartsInvented = {"line", "bar", "area", "pie"}
Records ],
IsDataScientist = true,
ChartsInvented = {"histogram"}
Table.FromRecords({
// Calculate grouped aggregations with Group()
BirthYear = 1759,
[
Table.Group(Musicians, "FirstName", each List.Min([BirthDate])
IsDataScientist = true,
BirthYear = 1759,
IsDataScientist = true,
Column manipulation
ChartsInvented = {"line", "bar", "area", "pie"}
Record.FromList(
// Add a column to a table with AddColumn()
// Change the order of columns with ReorderColumns()
Record.FromTable(
]},
Table.FromRecords({
SelectColumns()
Table.TransformColumns(
Table.FromColumns({
Text.Lower}}
})
{1759, 1857},
)
)
{true, true},
// Drop columns of a table with
{{"line", "bar", "area", "pie"}, {"histogram"}}
RemoveColumns()
[
Table.RemoveColumns(Musicians,
{"Name", "BirthYear", "IsDataScientist ", "ChartsInvented"}
]
{"William Playfair", 1759, true, {"line", "bar", "area", "pie"}},
Table Relations
{"Karl Pearson", 1857, true, {"histogram"}}
},
Example records
// Set as column as the secondary key with AddKey(, , false)
// Define a record
Example tables Table.AddKey(Albums, "ArtistID", false)
let
TaylorSwift = [
// Define tables
// Join two tables with Join()
FirstName = "Taylor",
let
Table.Join(Musicians, "ID", Albums, "ArtistID", JoinKind.LeftOuter)
LastName = "Swift",
Musicians = #table(
]
{
Pivoting
in
{1, "Taylor", "Swift", #date(1989, 12, 13)},
)
Table.Unpivot(Musicians, {"FirstName", "LastName"}, "NameType", "NameValue") // Returns table
Counting in
with FirstName and LastName on their own rows
Musicians
let
Record.FieldCount(TaylorSwift) // Returns 3
Albums = #table(
Table.Unpivot(MusiciansLong, {"FirstName", "LastName"}, "NameType", "NameValue") // Reverses
{"ID", "ArtistID", "Title"},
the unpivot step
// Determine if a record has a field name with HasFields()
{
{2, 2, "-"},
{3, 2, "5"}
Manipulation/Transformation }
in
Albums
Record.AddField(TaylorSwift, "MiddleName", "Alison")
Record.Combine(TaylorSwift)
Counting
// Remove fields with RemoveFields()
Record.RemoveFields(TaylorSwift)
Table.RowCount(Musicians) // Returns 2
Record.ReorderFields(TaylorSwift)
Table.ColumnCount(Musicians) // Returns 4
www.DataCamp.com
Table.Profile(Musicians) // Returns a table of min, max, mean, etc. by column
// Add a metadata record to a value with meta
ContentType = "quote",
Returns Musicians
Value.RemoveMetadata(curios)
SelectRows()
Table.Column(Musicians, "FirstName")