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.

Converting Numbers to Text

Suppose you have the number 100 and want 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”).

Converting Different Value Types

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

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

Creating a Descriptive Text String

The ability to convert different types of values into text is handy when you need to incorporate various value types into a single string. For instance, if you want to create a text string that describes the date stored in a column:

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

Handling Different Cultures

Cultures can have different standards for formatting dates or decimal separators. You can specify these using the optional culture argument.

Below, you’ll see the difference between using the English (US) and Dutch (NL) culture codes:

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

Handling Unsupported Value Types

It’s important to note that the Text.From function can’t handle every value. Trying to convert complex structures like lists, records, tables, functions, and types into text will lead to errors. Here 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:

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

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy