Text.From

Updated on

Text.From is a Power Query M function that converts a value to its text representation. The function returns the text representation of the input value, with an optional culture parameter to customize the conversion.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Text.From(
   value as any,
   optional culture as nullable text,
) as nullable text
ArgumentAttributeDescription
valueThe value to transform into text.
cultureoptionalThe culture argument enables the specification of a Culture code (e.g., “nl-NL” or “en-US”) to align transformations with local formatting conventions. If this argument is omitted, functions default to Culture.Current, which reflects the system’s regional settings.

Description

Returns the text representation of value. The value can be datetimedatetimedatetimezonelogical, duration or binary value. If the given value is null, Text.From returns null. An optional culture may also be provided (for example, “en-US”).

Examples

To better grasp the Text.From function’s functionality, let’s take a look at some real-world examples.

The purpose of this function is to convert a value into a text string. For instance, suppose you have the number 100 and wish to convert it into text. Here’s a simple way to do it:

Text.From( 100 ) // Output: "100"

The number 100 is initially a numeric value, but it’s now represented as a text string (“100”).

The beauty of Text.From is that it works seamlessly with other value types as well. Check out the examples below:

Text.From( 100 )                      // Output: "100"
Text.From( true ) )                   // Output: "true"
Text.From( #binary( "AQID" ) )        // Output: "AQID"
Text.From( #duration( 0, 1, 30, 0 ) ) // Output: "01:30:00"
Text.From( #time( 23, 30, 05 ) )      // Output: "11:30 PM"
Text.From( #date( 2023, 12, 25 ) )    // Output: "12/25/2023"
// Output: "2/26/2013 9:15:00 AM"
Text.From( #datetime( 2013, 02, 26, 09, 15, 00 ) ) 
// Output: "2/26/2013 9:15:00 AM +09:00"
Text.From( #datetimezone(2013, 02, 26, 09, 15,00, 09, 00 ) )
Text.From turns values into text in Power Query M

The ability to convert different types of values into text becomes especially handy when you need to incorporate various value types into a single string. Let’s assume you want to create a text string that describes the date stored in a column. You can achieve this by concatenating text with your date value:

// Output: "The date is 25-12-2023"
"The date is: "& Text.From( #date( 2023, 12, 25 ) ) 

Cultures can adopt their own standards for the formatting of dates or which decimal separator to use. In case you want to specify these you can use the optional culture argument.

Below image shows the difference between using the english (US) and the dutch (NL) culture code.

Text From en-US = Text.From( [Values], "en-US" )
Text From nl-NL = Text.From( [Values], "nl-NL" )
Text.From turns value into text respecting culture in Power Query M

It’s important to note that the Text.From function can’t handle every value. For example, trying to convert complex structures such as lists, records, tables, functions, and types into text leads to expression errors. Below are some examples:

// Expression.Error: We cannot convert a value of type List to type Text.
Text.From( { 1, 2, 3 } ) 

// Expression.Error: We cannot convert a value of type Record to type Text.
Text.From( [ A = 1, B = 2 ] )

// Expression.Error: We cannot convert a value of type Table to type Text.
Text.From( #table(  { "X", "Y" }, { { 0,1 }, { 1,0 } } ) )

// Expression.Error: We cannot convert a value of type Function to type Text.
Text.From( (x) => x + 1 )

// Expression.Error: We cannot convert Type to Text type.
Text.From( type date )

In these scenarios, the Text.From function will not be able to help. But as long as you keep in mind to apply the Text.From function to values it supports, it is a handy function to convert a variety of value types into text strings.

Learn more about Text.From in the following articles:

Other functions related to Text.From are:

BI Gorilla Blog

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/text-from