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.
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.
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.
let
List = {1..10}
in
List
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.
let
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}
in
List
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.
let
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”)
in
ExpandedSpeakerChildren
This is it for this blogpost. If you have any questions, just shoot!
© 2023 Kohera
Crafted by
© 2022 Kohera
Crafted by
Cookie | Duration | Description |
---|---|---|
ARRAffinity | session | ARRAffinity cookie is set by Azure app service, and allows the service to choose the right instance established by a user to deliver subsequent requests made by that user. |
ARRAffinitySameSite | session | This cookie is set by Windows Azure cloud, and is used for load balancing to make sure the visitor page requests are routed to the same server in any browsing session. |
cookielawinfo-checkbox-advertisement | 1 year | Set by the GDPR Cookie Consent plugin, this cookie records the user consent for the cookies in the "Advertisement" category. |
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
CookieLawInfoConsent | 1 year | CookieYes sets this cookie to record the default button state of the corresponding category and the status of CCPA. It works only in coordination with the primary cookie. |
elementor | never | The website's WordPress theme uses this cookie. It allows the website owner to implement or change the website's content in real-time. |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Cookie | Duration | Description |
---|---|---|
__cf_bm | 30 minutes | Cloudflare set the cookie to support Cloudflare Bot Management. |
pll_language | 1 year | Polylang sets this cookie to remember the language the user selects when returning to the website and get the language information when unavailable in another way. |
Cookie | Duration | Description |
---|---|---|
_ga | 1 year 1 month 4 days | Google Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors. |
_ga_* | 1 year 1 month 4 days | Google Analytics sets this cookie to store and count page views. |
_gat_gtag_UA_* | 1 minute | Google Analytics sets this cookie to store a unique user ID. |
_gid | 1 day | Google Analytics sets this cookie to store information on how visitors use a website while also creating an analytics report of the website's performance. Some of the collected data includes the number of visitors, their source, and the pages they visit anonymously. |
ai_session | 30 minutes | This is a unique anonymous session identifier cookie set by Microsoft Application Insights software to gather statistical usage and telemetry data for apps built on the Azure cloud platform. |
CONSENT | 2 years | YouTube sets this cookie via embedded YouTube videos and registers anonymous statistical data. |
vuid | 1 year 1 month 4 days | Vimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. |
Cookie | Duration | Description |
---|---|---|
ai_user | 1 year | Microsoft Azure sets this cookie as a unique user identifier cookie, enabling counting of the number of users accessing the application over time. |
VISITOR_INFO1_LIVE | 5 months 27 days | YouTube sets this cookie to measure bandwidth, determining whether the user gets the new or old player interface. |
YSC | session | Youtube sets this cookie to track the views of embedded videos on Youtube pages. |
yt-remote-connected-devices | never | YouTube sets this cookie to store the user's video preferences using embedded YouTube videos. |
yt-remote-device-id | never | YouTube sets this cookie to store the user's video preferences using embedded YouTube videos. |
yt.innertube::nextId | never | YouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen. |
yt.innertube::requests | never | YouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen. |
Cookie | Duration | Description |
---|---|---|
WFESessionId | session | No description available. |