#2 Lesson | Learn to Code with Microsoft M-Language: Write your first “Hello World!” Program

Almost every programing tutorial targeted at beginners starts with writing a simple, one line “Hello World!” program. So does mine.

Let’s open a new Excel Workbook. By default, you will see the Home Ribbon. Go to the Data Tab. If you don’t see the Data Tab, please watch the previous video which explains how to properly set up Excel (for Power BI users: You can follow my Excel based course for the most part, I might create a separate learning track targeted at you guys if needed).

On the Data Tab, select the Get Data icon.

Select Get Data > From Other Sources > Blank Query.

Now, click on the Advanced Editor icon.

This is where you are going to write your first “Hello World!” program.

Just very briefly for Power BI users: Double-click the desktop icon. By default, you are going to see the Home Ribbon. Go to the Get Data icon, select Get Data > Other > Blank Query and hit Connect. The Get Data command button is composed of two parts, an upper and lower one. Depending on which part you click, you will be presented a slightly different path to Blank Query.

On a side note: As you can see here, you can get data from a broad range of sources. And that’s where M-Language shines! It helps you clean up and harmonize different data sets before you can analyze them.

Once you hit connect, a Blank Query will open.

Next, click on the Advanced Editor icon.

Like I said before, I will be using Excel in the forthcoming sessions. But the environment you are going to work within does not vary much, whether you are using Excel or Power BI.

Now, let’s write your first line of code. This is the default code you will see first time you open up the Advanced Editor.

let
Source = ""
in
Source

Between the quotation marks, write Hello World! This is how your code should look like.

let
Source = "Hello World!"
in
Source

Next, hit Done.

Congrats! Your very first, tiny little “Hello World!” program was just executed. Now let’s examine what we just did. Click the angle bracket above Queries.

Right click the green field which says ABC Query1.

Select Advanced Editor and you should see your “Hello World!” code again.

let
Source = "Hello world!"
in
Source

First, let’s examine what you did. I will try using the correct terminology as much as I can, as defined in the Microsoft M-Language Specification. You can download the corresponding .pdf document here.

The terminology might be a bit confusing for you in the beginning (it was for me). What you just did is the following: You not just typed the word Hello World! You created a value “Hello World!”. There are different types of values as you will learn later. For now, let’s focus on the tiny little code you just wrote. The value “Hello World!” lives in a larger context. First, your value has a unique identifier.

“An identifier is a name used to refer to a value.” Microsoft M-Language Specification

Your value’s identifier is named Source. A value that has a unique identifier is called a variable. As you can see below, the building blocks of a variable are a value and its unique identifier, the latter two separated through an equal sign.

Next higher in your code’s hierarchy is the expression. You might feel tempted to refer to the structure of your code as to separate blocks.

However, the correct terminology here is: Let expression.

let
Source = "Hello World!"
in
Source
“The central construct in M is the expression. An expression can be evaluated (computed), yielding a single value. Although many values canbe written literally as an expression, a value is not an expression. For example, the expression 1 evaluates to the value 1; the expressions 1+1 evaluates to the value 2. This distinction is subtle, but important. Expressions are recipies for evaluation; values are the result of evaluation.” Microsoft M-Language Specification

Now, there is not much computation happening inside your “Hello World!” code. Let’s change that. Erase your variable and populate your Let expression als follows (bear in mind that multiple variables are separated by commas).

let
x = 1,
y = 2,
z = x + y
in
z

Hit Done and let’s see what happens.

We just created three different variables:

  • First, a variable with the identifier x and the value 1
  • Second, a variable with the identifier y and the value 2
  • Third, a variable with the identifier z composed of the two former variables

The entire computation performed here is called an expression which yields in the value 3. It’s important to understand these basic concepts. Fast forward a couple lessons, your code will look like this.

As confusing as it might look at first glance, it’s just a bigger Let expression than “Hello World!”, resulting in a single value. Speaking of values … ready to jump into the next lesson on values?

Let’s move on!

This is my entire course