Stop 05 · M Language & Advanced Power QueryTopics · 3/8

M Values: Lists, Records and Tables

Part of the Power BI Roadmap

In short

Lists, records and tables are the building blocks of everything in M. Once you can tell them apart, error messages like "We cannot convert a value of type List to type Table" finally make sense.

M works with a few structured values: lists in curly braces like {1, 2, 3}, records in square brackets like [City = "Pune"], and tables, which are made of rows that behave like records.

The jaadu sorts three piles on a desk: a long paper shopping list, a single visiting card, and a thick ledger whose pages are made of stacked cards.

Think of it like this

A shopping list, a contact card and a register

A shopping list is just items in order (a list). A visiting card has labelled fields like Name and City (a record). A shop's register is many such cards stacked in rows with the same labels (a table). Grab one column of the register and you get a list again.

Watch it happen

How the three values relate

Table: Sales
Row 0 = record
Column City = list
[City = "Pune"]
{"Pune", "Nagpur"}

1/5A table is rows and columns, like Sales with City and Amount.

The big ideas

What you need to know

Lists use { }

{1, 2, 3} or {"Pune", "Nagpur"}. {1..12} makes 1 to 12. Positions start at 0, so List{0} is the first item.

Records use [ ]

[Name = "Asha", City = "Pune"]. Read a field with Record[City].

Tables are rows of records

Table{0} returns the first row as a record. Table[Column] returns that column as a list.

Build a table by hand

#table({"City", "Sales"}, {{"Pune", 1200}, {"Nagpur", 900}}) creates a small table for testing.

See it in code

Walk through the code

powerquery
1let2    Branches = #table(3        {"City", "Sales"},4        {{"Pune", 120000}, {"Nagpur", 90000}, {"Nashik", 75000}}5    ),6    FirstRow = Branches{0},7    FirstCity = Branches{0}[City],8    AllSales = Branches[Sales],9    TotalSales = List.Sum(AllSales),10    Summary = [Branches = Table.RowCount(Branches), Total = TotalSales]11in12    Summary

1/4#table builds a table from a list of column names and a list of rows.

One query that touches all three value types and returns a record.

Save yourself the pain

Common mistakes

Oops

Expecting Table[Column] to give a table you can filter with Table.SelectRows.

Do this instead

It returns a list. Use List.Select on it, or keep it as a table with Table.SelectColumns.

Oops

Using Sales{1} to get the first row.

Do this instead

Positions start at 0. Sales{0} is the first row and Sales{1} is the second.

Your mission

Play with values in a blank query

~20 min

Quick check

What does Sales[Amount] return in M?

Go deeper

  1. 1Create a blank query that returns a list of numbers from 1 to 12.
  2. 2Build a small table with Table.FromRecords.
  3. 3Drill into one cell of a table and see it shown as a record.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge