Power Query: Fixed Expression
16 June 2021
Welcome to our Power Query blog. This week, I look at the M function Expression.Constant().
I have different types of constant data in each column as follows:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I am going to use the following function to show how data like this is created in M code:
Expression.Constant(value as any) as text
This returns the M source code representation of a constant value.
I will create a custom column on the ‘Add Column’ tab for each of my columns.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
The results for Last Name are:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
For text values, I get the original text in speech marks (“”). I would argue with the Microsoft definition, as the value returned is type Any, not Text. This process will be repeated if I apply Expression.Constant() to EC Last Name.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
Now I have two speech marks around each quotation mark. Curious to see what happens next? Me too…
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
So, I am adding two, then four, then eight speech marks. That’s enough for that one, I think. On to Employee ID:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
My numerical value is simply converted to type Any. Applying Expression.Constant() to EC Employee ID would just add speech marks and I don’t want to do that again!
The next column is Start Date:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
This time, the value returned is the M code that would be used to create the date from the base values of year, month and day.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
Similarly for Duration, I get the M code to create the duration from the number of days, hours, minutes and seconds.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/237/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
Finally, I get a similar result for Time, where I have the M code to create the time value from the number of hours, minutes and seconds.
Next time I’ll look at a related function Expression.Evaluate().
Come back next time for more ways to use Power Query!