Text.At

Updated on

Text.At is a Power Query M function that retrieves the character at a specified position within a text value. The function returns the character in the text value at the specified position, with positions starting at 0.

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

Syntax

Text.At(
   text as nullable text,
   index as number,
) as nullable text

Description

The Text.At function retrieves the character at the position index within the text parameter and returns it as a text value. It is important to note that positions in the text start from 0, meaning the first character is at position 0, the second character is at position 1, and so on.

Examples

Let’s delve into some examples to illustrate the usage of the Text.At function:

Suppose you have the text string “Hello, World” and you want to retrieve the character at position 4. By utilizing the Text.At function with the text “Hello, World” and an index of 4, you will obtain “o” as the resulting character.

Text.At( "Hello, World", 4 ) // Returns "o"

Consider the text “Run@”. If you need to extract the character at position 3 from this text, you can use the Text.At function with the text “Run@” and an index of 3. This will yield “@” as the retrieved character.

Text.At( "Run@", 3 )     // Returns "@"

In some scenarios, you may want to retrieve characters from a text value that includes leading or trailing spaces. For instance, if you have the text ” – – – “, and you wish to retrieve the character at position 1, Text.At with the text ” – – – ” and an index of 1 will give you “-” as the resulting character.

Text.At( " - - - ", 1 ) // Returns "-"

Learn more about Text.At in the following articles:

Other functions related to Text.At are:

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