The Text.At function in Power Query extracts a single character from a text string at a specified position. It requires a text value and a zero-based index (where 0 is the first character). If the index is out of range, it returns null. No special setup is needed beyond having Power Query available in Excel or Power BI.

What You'll Need

  • Access to Excel (2016 or later) or Power BI Desktop
  • A table or query with a text column you want to manipulate
  • Power Query Editor open (in Excel: Data > Get Data > Launch Power Query Editor; in Power BI: Home > Transform data)

Step-by-Step

  1. Open Power Query Editor and locate the query containing your text data. If you don’t have a query yet, load your data first (e.g., from Excel, CSV, or database).
  2. Identify the column you want to extract characters from. Note its exact column name—spaces and special characters matter.
  3. Click the column header to select the entire column.
  4. Go to the Add Column tab and select Custom Column (or right-click the column header and choose Add Column > Custom Column).
  5. In the Custom Column dialog box, enter a name for your new column (e.g., “FirstChar” or “CharAt3”).
  6. In the Custom column formula box, type the Text.At function. The syntax is: Text.At([ColumnName], Index). Replace [ColumnName] with your actual column name (including brackets) and Index with a number or formula. For example: Text.At([FullName], 0) returns the first character of FullName.
  7. Click OK. The new column appears with the extracted character. If the index is beyond the string length, the cell shows blank (null).
  8. To test with a variable index, replace the number with a column reference or expression. For example, Text.At([ProductName], [PositionIndex]) extracts the character at the position defined in the PositionIndex column.
  9. To handle errors where the index is too large, wrap the function in an if-statement: if [Index] < Text.Length([TextColumn]) then Text.At([TextColumn], [Index]) else null.
  10. Once satisfied, click Close & Load to apply the changes and return the updated table to Excel or Power BI.

Common Mistakes

  • Using 1-based indexing instead of 0-based: Text.At([Col], 1) returns the second character, not the first. Remember: position 0 is the first character.
  • Missing brackets around column names: [ColumnName] must be enclosed in square brackets in formulas. Typing Text.At(ColumnName, 0) causes an error.
  • Using negative indices: negative numbers are not allowed. Text.At([Col], -1) throws an error. Use Text.Length([Col]) - 1 for the last character instead.
  • Passing blank or null values: if the source text is null, Text.At throws an error. Use try Text.At([Col], 0) otherwise null or check with if [Col] = null then null else Text.At([Col], 0).
  • Assuming Text.At works with multi-character strings: it returns only one character. For substrings, use Text.Middle instead.

Tips

  • To extract the last character, use Text.At([Col], Text.Length([Col]) - 1).
  • To extract every odd-positioned character (positions 0, 2, 4…), create a custom column with Text.At([Col], Number.Even([Index]) * [Index] + Number.Odd([Index]) * ([Index] - 1)), or more simply, filter or generate a sequence column and apply Text.At conditionally.
  • Combine Text.At with Text.PositionOf to dynamically find a position: Text.At([Text], Text.PositionOf([Text], "X")) returns the character "X" itself (position of X, then extract at that index).
  • For case-sensitive extraction, no extra step is needed—Text.At is not case-sensitive in its operation, but the result depends entirely on the original text’s casing.
  • Use the fx button in the formula bar to insert Text.At from the list of functions, which auto-fills the syntax and helps avoid typos.
  • When working with Unicode or multibyte characters (e.g., emojis), remember Text.At counts code points, not visible glyphs. A single emoji may count as two characters (e.g., 👍 is one glyph but two code units in UTF-16).

Troubleshooting

If your Text.At formula returns an error or unexpected result, follow these steps:

  1. Check for #ERROR or #VALUE!: This usually means the index is out of range or a non-numeric value was passed. Ensure the index is a whole number and less than the text length. Use Text.Length([Col]) in a test column to verify lengths.
  2. Confirm column names match exactly. Power Query is case-sensitive in column references.
  3. Verify the data type. If the column is not of type Text (e.g., it’s Number or Date), convert it first: right-click the column > Change Type > Text.
  4. Watch for hidden characters. Leading/trailing spaces or non-printing characters can affect Text.Length. Clean the text first with Text.Trim([Col]) or Text.Clean([Col]) before applying Text.At.
  5. Test with hardcoded values. Replace [Col] with a literal string like "ABC" and index with 1 to confirm: Text.At("ABC", 1) should return "B". If it does, the issue is with the column or index logic.
  6. Use the Formula Bar to inspect intermediate values. Hover over a cell in the custom column to see the raw formula result, or add a temporary column with Text.Length([Col]) to debug index mismatches.
  7. If the function returns null unexpectedly, check if any source values are null or empty. Add a condition like if [Col] = "" then "" else Text.At([Col], 0) to handle empty strings.

Frequently Asked Questions

Does Text.At work with numbers?

No—Text.At only works on text. If your column contains numbers, convert it to text first using the Change Type option or the Text.From() function (e.g., Text.At(Text.From([NumberCol]), 1)).

Can I use Text.At to get the last character?

Yes. Use Text.At([Col], Text.Length([Col]) - 1). For example, if [Col] is "PowerQuery", Text.Length returns 10, so the index becomes 9 (the 10th character, since indexing starts at 0).

Why does Text.At([Col], 0) sometimes return nothing?

Only if [Col] is empty, null, or contains fewer than one character. An empty string has length 0, so index 0 is out of range, and Text.At returns null (displayed as blank).

Is Text.At case-sensitive?

No—the function itself does not perform case conversion. It returns exactly the character at that position, preserving its original case. If the text is "Hello", Text.At([Col], 0) returns "H", not "h".

How is Text.At different from Text.Middle?

Text.At extracts exactly one character at a given position. Text.Middle extracts a substring of a specified length starting at a position. For example, Text.Middle("Hello", 1, 2) returns "el", while Text.At("Hello", 1) returns "e".

Does Text.At support negative indexing like Python?

No—Power Query does not support negative indices in Text.At. To get characters from the end, calculate the index as Text.Length([Col]) - 1 for the last character, Text.Length([Col]) - 2 for the second-to-last, etc.