Power Query Beyond the Ribbon: Types

Some time ago I gave a session on SQL Server Days about Power Query. I really enjoyed speaking there. The title of the session was “Power Query Beyond The Ribbon”. I have to admit a major strength of Power Query is that you can do pretty much everything only by using the ribbon. However this doesn’t mean that learning something about M, the Power Query Formula Language, is a waste of time. With M you can solve some complex problems, automate parts or simplify your solution.

Before I move on, there is one thing you should always remember: M is case-sensitive! A bit of a pain, since we don’t have intellisense for the moment. Just be very meticulous.

Simple literals

The first time I wanted to do something with a script in Power Query, I needed to add a specific date. I searched the internet to find the proper function. I went through the complete Power Query Formula Categories and didn’t find a thing. An uploaded Powerpoint with some examples in it provided me the necessary information. To give you a little help I will give you a list of some literals you can use.


Complex types

It is also possible to instantiate more complex types with some simple code. ‘List’ and ‘Record’ were very intuitive to me, while ‘Table’ is a combination of some different elements.


To see the result of a list, you can test it by writing something like this in the Advanced Editor.

List = {1..10}

With this short example you can see the normal layout of Power Query code. We have the ‘let’-part were we put all our logic and we have the ‘in’-part to choose our output. This layout remains the same for more complex solutions. If I expand this first example, you will see what I mean. To see what happens on every line, just change the output at the bottom to the name of the step you want to see. I can already tell you that ‘TableFromRecords’ will return an error line, since not all elements of the record have a value. Although the result is similar, this is a different behavior than ‘TableFromList’ combined with ‘ExpandColumn’. Always check which solution is best for your case.

List = {1..10},
PersonRecord = [Name = “Ken” , Age = 36],
RecordWithList = [x = 1, y = {1..5}],
ListOfRecords = {[Name = “Ken” , Age = 36], [Name = “Nicole”]},
TableFromList = Table.FromList(ListOfRecords, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ExpandColumn = Table.ExpandRecordColumn(TableFromList, “Column1”, {“Name”, “Age”}, {“Column1.Name”, “Column1.Age”}),
TableFromRecords = Table.FromRecords(ListOfRecords),
TableFromRecords2 = Table.FromRecords({[Name = “Ken” , Age = 36], [Name = “Nicole”, Age = null]}),
TableFromScratch = #table({“Name”, “Age”}, {{“Ken”, 36}, {“Nicole”, null}}),
ListValue5 = List {5},
ListOfRecordsValue0 = ListOfRecords{0}

Structured Types

The last type you can find in Power Query is a Structured Type. We have three different types: List Type, Record Type and Table Type. With Structured Types it is possible to split the definition of a List/Record/Table from the creation of the actual List/Record/Table. It was very hard to find information about them and how you could use it. Best way to show you what they are is give you an example. In the example we use all three types, create a table and then open record and list to show the content.

NameList = type {text},
PersonRecord = type [name = text, age = number, children = NameList ],
PersonTable = type table [Speaker = PersonRecord],
TableCreation = #table ( PersonTable, {{ [name = “Ken”, age = 37, children = {“Tess”, “Shrimp”}] }}) ,
ExpandedSpeaker = Table.ExpandRecordColumn(TableCreation, “Speaker”, {“name”, “age”, “children”}, {“Speaker.name”, “Speaker.age”, “Speaker.children”}),
ExpandedSpeakerChildren = Table.ExpandListColumn(ExpandedSpeaker, “Speaker.children”)

This is it for this blogpost. If you have any questions, just shoot!

Your Modernization Journey starts now
Recently Microsoft introduced SQL server 2022. We wrote this post to make sure you won’t be missing out on all the fun and exciting new...
Parameter sniffing solved with new Parameter Sensitive Plan Optimization feature
If you’re someone that works a lot with Microsoft SQL Server, there’s no doubt that you’ve had issues with an issue called “Parameter sniffing” before....
Creating maps with R and Power BI
The possibilities are infinite when it comes to creating custom visuals in Power BI. As long as you are creative and have knowledge about the...
Reading monitoring alerts in Telegram
Sending monitoring alerts through Telegram
What if you could get the ease of phone notifications for whatever monitoring alerts you need? Then we have a solution for you with the...
Send mails with Azure Elastic Database Jobs
The DatabaseMail feature in SQL Server and Managed Instance is widely used by many professionals. But what if you want similar functionality in Azure SQL...
Sorting matrices in Power BI
Recently I worked on a Power BI project for a client. They had a SharePoint site where they regularly published articles and wanted to pour...