Text.From

D

T

The M Code Behind the Power Query M function Text.From

In this article, we will explore the M code behind the Text.From function and learn how it works to convert different data types into text.

What is the Text.From Function?

The Text.From function is a Power Query M function that takes a value as input and returns its text representation. It is a versatile function that can handle values of various data types, such as numbers, dates, lists, tables, and more.

The Text.From function is typically used in data transformation scenarios where we need to convert non-text values into text for further processing or analysis. For instance, we may want to convert a numeric value into a text string to concatenate it with other text values or convert a date value into a specific text format.

Syntax of Text.From Function

The syntax of the Text.From function is straightforward. It takes a single argument, which is the value to be converted into text.


Text.From(value as any) as text


The argument “value” can be of any data type, and the function returns the text representation of the input value. The output is always a text string, even if the input is already a text string.

How Text.From Works

The Text.From function works by applying the appropriate conversion logic based on the input data type. It uses a set of built-in conversion rules to transform each data type into its corresponding text representation.

Let’s take a look at some examples of how Text.From works with different data types:

Converting Numbers into Text

When we pass a numeric value to the Text.From function, it converts it into a text string by default. For instance, the expression Text.From(123) returns “123”.

However, we can also specify a specific format for the output text string using the optional second argument of the Text.From function. For example, the expression Text.From(123, “0.00”) returns “123.00”.

Converting Dates into Text

When we pass a date value to the Text.From function, it converts it into a text string using the default date format (“yyyy-mm-dd”). For instance, the expression Text.From(#2020-12-31#) returns “2020-12-31”.

However, we can also specify a custom date format using the optional second argument of the Text.From function. For example, the expression Text.From(#2020-12-31#, “dd/mm/yyyy”) returns “31/12/2020”.

Converting Lists into Text

When we pass a list of values to the Text.From function, it converts each value into a text string and concatenates them into a single text string. For instance, the expression Text.From({1, 2, 3}) returns “1, 2, 3”.

Converting Tables into Text

When we pass a table to the Text.From function, it converts it into a text string by concatenating each row into a single text string. For instance, the expression Text.From(Table.FromRecords({[A=1, B=2], [A=3, B=4]})) returns “A,Brn1,2rn3,4”.

The Text.From function is a powerful M function in Power Query that allows us to convert various data types into text strings. It is a versatile function that is widely used in data transformation, cleansing, and modeling.

In this article, we have explored the M code behind the Text.From function and learned how it works to convert different data types into text. We have seen that the function applies a set of built-in conversion rules to transform each data type into its corresponding text representation.

Next time you need to convert a non-text value into text in Power Query, remember to use the Text.From function and its optional format argument to get the desired output.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)