{"id":1685,"date":"2020-08-14T13:21:05","date_gmt":"2020-08-14T13:21:05","guid":{"rendered":"https:\/\/bi.unija.com\/en\/?p=1685"},"modified":"2020-08-17T13:58:15","modified_gmt":"2020-08-17T13:58:15","slug":"introduction-to-m-language","status":"publish","type":"post","link":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/","title":{"rendered":"Introduction to M language"},"content":{"rendered":"<p><em>For Power BI version 2.76.5678.782 (December 2019).<\/em><\/p>\n<p>Query editor is a capable data editor in Power BI Desktop. Transformations made in Power Query are written in M language. Understanding M is not necessary, but can be a powerful asset for advanced data manipulation. Let&#8217;s look at basics of working with M language.<\/p>\n<h1>M query structure<\/h1>\n<p>M code can be found by selecting a query and then opening <strong>Advanced Editor<\/strong>. Code usually starts with <strong>let<\/strong> and ends with <strong>in<\/strong> statement.<\/p>\n<ul>\n<li><strong>let<\/strong> part contain all the steps query makes. Each line contains one step.<\/li>\n<li><strong>in<\/strong> part contains the name of the last step.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1330\" height=\"512\" class=\"wp-image-1686\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-70.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-70.png 1330w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-70-300x115.png 300w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-70-1024x394.png 1024w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-70-768x296.png 768w\" sizes=\"(max-width: 1330px) 100vw, 1330px\" \/><\/p>\n<p>Entire code of a query could be read as &#8220;<strong>let&#8221; <\/strong>step1, step2, step3 be <strong>&#8220;in&#8221; <\/strong>step3.<\/p>\n<h1>Variables<\/h1>\n<p>Every row starts with step&#8217;s name and ends with comma, except for the last row that doesn&#8217;t end with a comma. Step names are identical to step names in <strong>Applied Steps<\/strong> pane.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1132\" height=\"510\" class=\"wp-image-1687\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-71.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-71.png 1132w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-71-300x135.png 300w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-71-1024x461.png 1024w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-71-768x346.png 768w\" sizes=\"(max-width: 1132px) 100vw, 1132px\" \/><\/p>\n<p>If variable name contains space it will appear in M code as <strong>#&#8221;Ime spremenljivke&#8221;<\/strong>. This is how M engine handles spaces and understands it is still a single name.<\/p>\n<h1>Comments<\/h1>\n<p>As in most languages, we can write comments in M code.<\/p>\n<ul>\n<li>For one line comments we use \/\/.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"137\" class=\"wp-image-1688\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-72.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-72.png 653w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-72-300x63.png 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/p>\n<ul>\n<li>For multiple line comments we use \/* in *\/.<\/li>\n<\/ul>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"656\" height=\"229\" class=\"wp-image-1689\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-73.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-73.png 656w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-73-300x105.png 300w\" sizes=\"(max-width: 656px) 100vw, 656px\" \/><\/strong><\/p>\n<h1>M functions<\/h1>\n<p>M has more than 700 functions for data editing. M functions start with capital letters, words are separated by full stop. Arguments are given in brackets.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"182\" class=\"wp-image-1690\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-74.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-74.png 655w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-74-300x83.png 300w\" sizes=\"(max-width: 655px) 100vw, 655px\" \/><\/strong><\/p>\n<p>Example: function <strong>Date.Month(date)<\/strong>, takes an argument date and returns date month.<\/p>\n<p>Function names are descriptive enough to convey their function. Most commonly used functions are already available through icons in Power Query editor. Documentation and examples for each function can be found on <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerquery-m\/power-query-m-function-reference\">https:\/\/docs.microsoft.com\/en-us\/powerquery-m\/power-query-m-function-reference<\/a>.<\/p>\n<h1>Values<\/h1>\n<p>When we wish to operate with actual values we have to use appropriate commands. For example, to use the date 6\/27\/2917, we use <strong>#date(2017, 6, 26)<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"182\" class=\"wp-image-1691\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-75.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-75.png 655w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/word-image-75-300x83.png 300w\" sizes=\"(max-width: 655px) 100vw, 655px\" \/><\/p>\n<p>Other value commands are listed in the table below.<\/p>\n<table>\n<tbody>\n<tr>\n<td>Value<\/td>\n<td>Syntax<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>null<\/td>\n<\/tr>\n<tr>\n<td>Logic<\/td>\n<td>true, false<\/td>\n<\/tr>\n<tr>\n<td>Number<\/td>\n<td>0, 1, -1, 1.5, 3.1e^-20<\/td>\n<\/tr>\n<tr>\n<td>Time<\/td>\n<td>#time(01, 12, 50)<\/td>\n<\/tr>\n<tr>\n<td>Date<\/td>\n<td>#date(2012, 1, 20)<\/td>\n<\/tr>\n<tr>\n<td>Date-time<\/td>\n<td>#datetime(2012, 1, 20, 01, 12, 50)<\/td>\n<\/tr>\n<tr>\n<td>Text<\/td>\n<td>&#8220;text&#8221;<\/td>\n<\/tr>\n<tr>\n<td>List<\/td>\n<td>{1, 2, 3}<\/td>\n<\/tr>\n<tr>\n<td>Row<\/td>\n<td>[ A = 1, B = 2 ]<\/td>\n<\/tr>\n<tr>\n<td>Table<\/td>\n<td>#table({&#8220;A&#8221;, &#8220;B&#8221;},{{ 1, 2 }, { 3, 4 }})<\/td>\n<\/tr>\n<tr>\n<td>Function<\/td>\n<td>(parameter) =&gt; parameter +1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For Power BI version 2.76.5678.782 (December 2019). Query editor is a capable data editor in Power BI Desktop. Transformations made in Power Query are written in M language. Understanding M is not necessary, but can be a powerful asset for<\/p>\n","protected":false},"author":5,"featured_media":1692,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[7,9],"class_list":["post-1685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-advanced","tag-m","tag-power-query"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Introduction to M language - Bi Unija<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to M language - Bi Unija\" \/>\n<meta property=\"og:description\" content=\"For Power BI version 2.76.5678.782 (December 2019). Query editor is a capable data editor in Power BI Desktop. Transformations made in Power Query are written in M language. Understanding M is not necessary, but can be a powerful asset for\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/\" \/>\n<meta property=\"og:site_name\" content=\"Bi Unija\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-14T13:21:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-17T13:58:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/19eng.png\" \/>\n\t<meta property=\"og:image:width\" content=\"720\" \/>\n\t<meta property=\"og:image:height\" content=\"480\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Branka Trifunovi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Branka Trifunovi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/\",\"url\":\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/\",\"name\":\"Introduction to M language - Bi Unija\",\"isPartOf\":{\"@id\":\"https:\/\/bi.unija.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/19eng.png\",\"datePublished\":\"2020-08-14T13:21:05+00:00\",\"dateModified\":\"2020-08-17T13:58:15+00:00\",\"author\":{\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10\"},\"breadcrumb\":{\"@id\":\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#primaryimage\",\"url\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/19eng.png\",\"contentUrl\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/19eng.png\",\"width\":720,\"height\":480},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/bi.unija.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Introduction to M language\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/bi.unija.com\/en\/#website\",\"url\":\"https:\/\/bi.unija.com\/en\/\",\"name\":\"Bi Unija\",\"description\":\"Just another Bi site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/bi.unija.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10\",\"name\":\"Branka Trifunovi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g\",\"caption\":\"Branka Trifunovi\u0107\"},\"url\":\"https:\/\/bi.unija.com\/en\/author\/branka\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to M language - Bi Unija","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to M language - Bi Unija","og_description":"For Power BI version 2.76.5678.782 (December 2019). Query editor is a capable data editor in Power BI Desktop. Transformations made in Power Query are written in M language. Understanding M is not necessary, but can be a powerful asset for","og_url":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/","og_site_name":"Bi Unija","article_published_time":"2020-08-14T13:21:05+00:00","article_modified_time":"2020-08-17T13:58:15+00:00","og_image":[{"width":720,"height":480,"url":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/19eng.png","type":"image\/png"}],"author":"Branka Trifunovi\u0107","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Branka Trifunovi\u0107","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/","url":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/","name":"Introduction to M language - Bi Unija","isPartOf":{"@id":"https:\/\/bi.unija.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#primaryimage"},"image":{"@id":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#primaryimage"},"thumbnailUrl":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/19eng.png","datePublished":"2020-08-14T13:21:05+00:00","dateModified":"2020-08-17T13:58:15+00:00","author":{"@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10"},"breadcrumb":{"@id":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bi.unija.com\/en\/introduction-to-m-language\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#primaryimage","url":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/19eng.png","contentUrl":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/08\/19eng.png","width":720,"height":480},{"@type":"BreadcrumbList","@id":"https:\/\/bi.unija.com\/en\/introduction-to-m-language\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bi.unija.com\/en\/"},{"@type":"ListItem","position":2,"name":"Introduction to M language"}]},{"@type":"WebSite","@id":"https:\/\/bi.unija.com\/en\/#website","url":"https:\/\/bi.unija.com\/en\/","name":"Bi Unija","description":"Just another Bi site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bi.unija.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10","name":"Branka Trifunovi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g","caption":"Branka Trifunovi\u0107"},"url":"https:\/\/bi.unija.com\/en\/author\/branka\/"}]}},"_links":{"self":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1685"}],"collection":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/comments?post=1685"}],"version-history":[{"count":3,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1685\/revisions"}],"predecessor-version":[{"id":1696,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1685\/revisions\/1696"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/media\/1692"}],"wp:attachment":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/media?parent=1685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/categories?post=1685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/tags?post=1685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}